Help with program

Discussion in 'Mac Programming' started by bravens52, Mar 5, 2010.

  1. bravens52 macrumors regular

    Joined:
    Jul 16, 2009
    #1
    hey guys i have a c++ program due tonight for class and im geting a errors that i dont know how to fix and was wondering can somebody look at my program and look at the errors and perhaps fix them.



    Code:
    #include <iomanip>
    #include <iostream>
    #include <fstream>
    
    using namespace std; 
    
    bool myIsAlpha( char ch );
    bool myIsDigit( char ch );
    bool myIsUpper( char ch );
    
    int main () 
    {
    	
    char ch;	
    	ifstream inputFile( "input.txt" );
    inputFile.get(ch);
    	
    	inputFile.open ( "input.txt" );
    	if (inputFile.fail() )
    	{
    		cout << "input.txt failed to open";
    		exit ( -1 );
    		}
    	
    	
    	int Alpha;
    	int Upper;
    	int Lower;
    	int Digit;
    	int White;
    	int Space;
    	int Total;
    	
    	Alpha = 0;
    	Upper = 0;
    	Lower = 0;
    	Digit = 0;
    	White = 0;
    	Space = 0;
    	Total = 0;
    	
    	cout << "Alpha";
    	cin >> ch;
    	cout << "Total";
    	cin >> ch;
    	cout << "Upper";
    	cin >> ch;
    	cout << "Lower";
    	cin >> ch;
    	cout << "Digit";
    	cin >> ch;
    	cout << "Space";
    	cin << ch;	
    	
    while (inputFile)
    {
    	Total++;
    	cout << ch;
    		if(myIsAlpha(ch))
    		{
    			Alpha++;
    			cout << ch;
    			if(myIsUpper(ch))
    				Upper++;
    			cout << ch;
    		}
    		else 
    		{
    			Lower++;
    			cout << ch;
    		}
    		
    		else if (myIsDigit(ch))
    		{
    				Digit ++;
    			cout << ch;
    		}
    	else if (isspace(ch))
    	{
    		White++;
    		cout << ch;
    			if (ch== ' ')
    				Space++;
    		cout << ch;
    	}
    	
    
    	
    	return 0;
    }
    
    	bool  myIsAlpha( char ch )
    		{
    			if (ch > 'a' && ch <= 'z' || ch>='A' && ch <= 'Z')
    				return true;
    			else 
    				return false;
    		}
    	bool myIsDigit ( char ch )
    		{
    			if (ch >= '0' && ch <= '9')
    				return true;
    			else 
    				return false;
    		}
    			
    			
    	bool myIsUpper ( char ch )
    	{
    	if ( ch >= 65 && ch <= 90)
    				
    				return true;
    			else
    				return false;
    	}
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Tell us what the errors are. Tell us what you've tried to do to fix them, and what effect was wrought. Tell us what the program is supposed to do. Tell us what it does do. Post the data file you're testing with, what result you're getting with it and what you think you should get.

    We'll help with HW, but we need more information and we won't do it for you. Also, bad timing posting the night this is due. You knew before now you had problems.

    -Lee

    edit:
    also, code tags: [CODE][/CODE]
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    Can't look at the errors. You didn't post any.

    Can't fix errors. You didn't tell us what the program should do.

    Can't do any trial runs after fixing errors. You didn't post your data file.


    When I put your code into a file and compile it in Terminal, like so:
    Code:
    g++ flunking.cpp
    
    these errors come up:
    Code:
    flunking.cpp: In function 'int main()':
    flunking.cpp:53: error: no match for 'operator<<' in 'std::cin << ch'
    flunking.cpp:73: error: expected `}' before 'else'
    flunking.cpp:73: error: expected `}' before 'else'
    flunking.cpp: At global scope:
    flunking.cpp:73: error: expected unqualified-id before 'else'
    flunking.cpp:78: error: expected unqualified-id before 'else'
    flunking.cpp:89: error: expected unqualified-id before 'return'
    flunking.cpp:90: error: expected declaration before '}' token
    
    Every one of these seems self-evident to me, and you should be able to fix them one by one.

    If the problem isn't evident when you go to each line (the number between the :'s, following the filename), then it suggests you should study that particular thing until it does become evident.
     
  4. bravens52 thread starter macrumors regular

    Joined:
    Jul 16, 2009
  5. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #5
    So, it seems you have put off your homework until the last minute, and now can't/won't find a TA that is willing to help you. And you want us to fix your homework for you? I think you are missing much of the point of the whole exercise of college.
     
  6. lloyddean macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #6
    Good luck, and please do let us know what you ended up turning in!!!
     
  7. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #7
    Errors actually do tell you what the problem is. You just need to sit down and think about them for a minute. Granted, GCC does not have the clearest error messages in the world sometimes.

    Why don't you try compiling with Clang / LLVM? The clearer error messages may help you to fix the problems by yourself.
     

Share This Page