dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] Begginer needs help please

  1. #1
    Join Date
    Apr 2008
    Posts
    6

    [RESOLVED] Begginer needs help please

    hello to all. i just signed up to this forum after referencing it many times to help with various programs for a class of mine. this is my first post so bear with me. i just started working on this code a little bit ago but when i try to test it i get the following errors.


    Compiling...
    HomeworkVogt10.cpp
    F:\Flash Drive\Lexar (F)\Adams Stuff\Comp. Sci\CSC144_S08\HMWK ASSIGNMENTS\HomeworkVogt10.cpp(45) : error C2143: syntax error : missing ')' before 'constant'
    F:\Flash Drive\Lexar (F)\Adams Stuff\Comp. Sci\CSC144_S08\HMWK ASSIGNMENTS\HomeworkVogt10.cpp(45) : error C2143: syntax error : missing ';' before 'constant'
    F:\Flash Drive\Lexar (F)\Adams Stuff\Comp. Sci\CSC144_S08\HMWK ASSIGNMENTS\HomeworkVogt10.cpp(45) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    HomeworkVogt10.exe - 3 error(s), 0 warning(s)


    ive checked other threads so try to find the problem but i cannot seem to figure it out...i have attatched my code but i saw in the faq there was a specific way to embed code in the post? sorry i would if i knew how : /. any help would be greatly appreciated.





    #include <iostream> //this is a preprocessor directive to use cout
    using namespace std;

    #define NumOfQuestions 20

    void GetScores (char [],int);
    void CompareAnswers (char [],char[],int);

    ////////////////////////////////////////////////////////////////////////


    void main (void)
    {
    int Counter = 1;
    char StudentsAnswers[NumOfQuestions];
    char CorrectAnswers[NumOfQuestions] =
    {'B','D','A','A','C',
    'A','B','A','C','D',
    'B','C','D','A','D',
    'C','C','B','D','A',};




    for(Counter = 1; Counter <=NumOfQuestions; Counter++)
    { cout<<"Enter your answer for number "<<Counter;
    cout<<"\nIt must be either A, B, C, or D.\n";
    cin>>StudentsAnswers[Counter];
    }

    // GetScores (StudentsAnswers, NumOfQuestions);
    // CompareAnswers (StudentsAnswers,CorrectAnswers, NumOfQuestions);
    }

    //////////////////////////////////////////////////////////////////////////
    void GetScores (char StudentAnswers[], int NumOfQuestions)
    {
    for(Counter = 1; Counter <=NumOfQuestions; Counter++)
    { cout<<"Enter your answer for number "<<Counter;
    cout<<"\nIt must be either A, B, C, or D.\n";
    cin>>StudentsAnswers[Counter];
    }


    }


    //////////////////////////////////////////////////////////////////////////
    void CompareAnswers (char StudentsAnswers[], char CorrectAnswers[], int NumOfQuestions)
    {
    int Counter = 1;


    for(Counter = 1; Counter<=NumOfQuestions; Counter++)
    { cout<<CorrectAnswers[Counter]<<endl;



    }







    }
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Begginer needs help please

    Hard to read without code tags, but I think the error is due to the extra comma in your declaration of CorrectAnswers[].

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,581

    Re: Begginer needs help please

    The problem is in using NumOfQuestions (which is #defined as 20) as the int argument in CompareAnswers() and GetScores() definitions!
    Use some other identificator, for example NoOfQuestions.
    Last edited by VictorN; April 23rd, 2008 at 09:41 AM.
    Victor Nijegorodov

  4. #4
    Join Date
    Apr 2008
    Posts
    6

    Re: Begginer needs help please

    hmm...i tried both those suggestions and when i compile i still get the same three errors...if anyone could inform me on how to embed code on the post i will try to and see if that helps you guys read it easier...thanks

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,581

    Re: Begginer needs help please

    Show your changed code
    Victor Nijegorodov

  6. #6
    Join Date
    Apr 2008
    Posts
    6

    Re: Begginer needs help please

    i will be glad to. i just figure it would be clearer if i knew how to put the code in the correct format for posting...but i dont : (

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Begginer needs help please

    [code ] [/code ] without spaces. And indent it.

  8. #8
    Join Date
    Apr 2008
    Posts
    6

    Re: Begginer needs help please

    ok here goes

    Code:
    #include <iostream>    //this is a preprocessor directive to use cout
    using namespace  std;
    
    #define NoOfQuestions 20
    
    void GetScores (char [],int);
    void CompareAnswers (char [],char[],int);
    
    ////////////////////////////////////////////////////////////////////////
    
    
    void main (void)
    {
    	int Counter = 1;
    	char StudentsAnswers[NoOfQuestions];
    	char CorrectAnswers[NoOfQuestions] =
    			{'B','D','A','A','C',
    			 'A','B','A','C','D',
    			 'B','C','D','A','D',
    			 'C','C','B','D','A'};
    
    
    
    
    for(Counter = 1; Counter <=NoOfQuestions; Counter++)
    	{	cout<<"Enter your answer for number "<<Counter;
    		cout<<"\nIt must be either A, B, C, or D.\n"; 
    		cin>>StudentsAnswers[Counter];
    	}	
    
    	//	GetScores (StudentsAnswers, NumOfQuestions)
    	//	CompareAnswers (StudentsAnswers,CorrectAnswers, NumOfQuestions)
    }
    
    //////////////////////////////////////////////////////////////////////////
    
    void GetScores (char StudentAnswers[], int NoOfQuestions)
    {
    	for(Counter = 1; Counter <=NoOfQuestions; Counter++)
    	{	cout<<"Enter your answer for number "<<Counter;
    		cout<<"\nIt must be either A, B, C, or D.\n"; 
    		cin>>StudentsAnswers[Counter];
    	}
    
    
    }
     
    
    //////////////////////////////////////////////////////////////////////////
    void CompareAnswers (char StudentsAnswers[], char CorrectAnswers[], int NoOfQuestions)
    {
    int Counter = 1;
    
    
    	for(Counter = 1; Counter<=NoOfQuestions; Counter++)
    	{	cout<<CorrectAnswers[Counter]<<endl;
    	
    	
    	
    	}
    
    
    
    
    
    
    
    }


    im thinking that i just misunderstood VictorN somehow...

    p.s. all 3 errors are on the definition line of getScores if that helps...
    Last edited by adamvogt28; April 23rd, 2008 at 11:35 AM.

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,559

    Re: Begginer needs help please

    Your function argument needs to be different than your #define. You should have only changed one of them.

  10. #10
    Join Date
    Apr 2008
    Posts
    6

    Re: Begginer needs help please

    perfect. thanks a ton guys.

  11. #11
    Join Date
    Apr 2008
    Posts
    6

    Re: [RESOLVED] Begginer needs help please

    i think the errors were just kind of misleading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)