noob needs code check...

This is a discussion on noob needs code check... within the C++ Programming forums, part of the General Programming Boards category; Please tell me what I'm missing. Code: //This is to calculate the average of up to 100 test scores. #include ...

  1. #1
    False Return hubris's Avatar
    Join Date
    Apr 2009
    Posts
    33

    noob needs code check...

    Please tell me what I'm missing.

    Code:
    //This is to calculate the average of up to 100 test scores.
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	double average = 0;      //My established variables, initialized.
    	int noscores = 1;
    	int scores = 0;
    	double inscore = 0;
    	double scoresum = 0;
    	
    	cout << setprecision(2);    // Moderate precision setting
    	cout << "Please enter the number of test scores, (up to 100):  "  << endl;
    	cin >> noscores;
    	if (noscores < 100);
    	   cout << "Please enter a test score:  "  << endl;
    	   cin >> inscore;
    	{	 
    		if (scores = noscores);
    		cout << "Your score average is:  " << average << endl;
    		average = scoresum / noscores;
    		else cout << "Please enter a test score:  "  << endl;
    			 cin >> inscore;
    		     scoresum = scoresum + inscore; 
    		     scores = scores + 1;
    		}
    	else cout << "Error:  User input excedes program parameter." << endl;     
    	
    		    
    	    return(0);}
    Any help is golden

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It would of course help quite a bit if we knew what the program is supposed to do - you may be misisng 1000 lines of code (or many many more than that), or it may be complete. Depends entirely on what the original problem to solve is defined as.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Code:
    if (noscores < 100);
    The semicolon there means that nothing should be done if the condition is true. Using braces around blocks also helps.

    Code:
    if (scores = noscores);
    Same mistake and mixing up == and =.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,167
    Also, fix your indentation. It can help you uncover errors.

  5. #5
    False Return hubris's Avatar
    Join Date
    Apr 2009
    Posts
    33

    K, but....

    the error I'm getting is a declaration that my else statement doesn't have a matching if, which...it does.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Location
    ...creepy
    Posts
    75
    its because in this line

    if (scores = noscores);
    you have a semicolon after the if statement. take that out and then put brackets after this and then close that bracket where needed. I haven't checked the code or anything to see if it works, and i dont know what the program is supposed to do, but maybe that's the problem...

  7. #7
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,238
    Quote Originally Posted by hubris View Post
    the error I'm getting is a declaration that my else statement doesn't have a matching if, which...it does.
    Because you have semicolons where you shouldn't, and you have no braces where you should. Indenting the code properly would reveal that.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Registered User
    Join Date
    Apr 2009
    Location
    ...creepy
    Posts
    75
    Amen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM
  5. Check my code Please
    By AdioKIP in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2002, 07:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21