943,528 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 580
  • C++ RSS
Oct 21st, 2008
0

Help with code please

Expand Post »
Can someone take a look at my code and see if they notice something wrong.

int score;
	 char grade =0;

     // read in total score 

     cout << endl;
     cout << "Enter total score (float, must be <= 100): "; 
     cin >> score;  
     
     if (score >= 85); 
        grade = 'A';
	 else if (score >= 75); 
        grade = 'B';
	 else if (score >= 65); 
        grade = 'C';
	 else if (score >= 55);
	    grade = 'D';
	 else 
	    grade = 'F';
	 End if // score >= 55
     End if // score >= 65
     End if // score >= 75
     End if // score >= 85



     // display the result 

	 cout << endl; 
     cout << "Your grade for CMSC 101 is: " << grade << endl; 
     return (0); // terminate with success
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dtaylor01 is offline Offline
10 posts
since Oct 2008
Oct 21st, 2008
0

Re: Help with code please

C and C++ do not have "END IF" statements.
C++ Syntax (Toggle Plain Text)
  1. int score;
  2. char grade =0;
  3.  
  4. // read in total score
  5.  
  6. cout << endl;
  7. cout << "Enter total score (float, must be <= 100): ";
  8. cin >> score;
  9.  
  10. if (score >= 85);
  11. grade = 'A';
  12. else if (score >= 75);
  13. grade = 'B';
  14. else if (score >= 65);
  15. grade = 'C';
  16. else if (score >= 55);
  17. grade = 'D';
  18. else
  19. grade = 'F';
  20.  
  21. // display the result
  22.  
  23. cout << endl;
  24. cout << "Your grade for CMSC 101 is: " << grade << endl;
  25. return (0); // terminate with success
Last edited by Ancient Dragon; Oct 21st, 2008 at 11:53 pm.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Oct 22nd, 2008
1

Re: Help with code please

Take away all those semi-colons after the if and else-if statement:

C++ Syntax (Toggle Plain Text)
  1. if (score >= 85);
  2. grade = 'A';
  3. else if (score >= 75);
  4. grade = 'B';
  5. else if (score >= 65);
  6. grade = 'C';
  7. else if (score >= 55);
  8. grade = 'D';
  9. else
  10. grade = 'F';
Reputation Points: 118
Solved Threads: 15
Posting Pro in Training
Denniz is offline Offline
428 posts
since Sep 2008
Oct 22nd, 2008
0

Re: Help with code please

Click to Expand / Collapse  Quote originally posted by dtaylor01 ...
Can someone take a look at my code and see if they notice something wrong.

int score;
	 char grade =0;

     // read in total score 

     cout << endl;
     cout << "Enter total score (float, must be <= 100): "; 
     cin >> score;  
     
     if (score >= 85); 
        grade = 'A';
	 else if (score >= 75); 
        grade = 'B';
	 else if (score >= 65); 
        grade = 'C';
	 else if (score >= 55);
	    grade = 'D';
	 else 
	    grade = 'F';
	 End if // score >= 55
     End if // score >= 65
     End if // score >= 75
     End if // score >= 85



     // display the result 

	 cout << endl; 
     cout << "Your grade for CMSC 101 is: " << grade << endl; 
     return (0); // terminate with success
Start using C++....when posting in the C++ section
Reputation Points: 46
Solved Threads: 8
Junior Poster
sidatra79 is offline Offline
114 posts
since Feb 2008
Oct 22nd, 2008
0

Re: Help with code please

C++ Syntax (Toggle Plain Text)
  1. int score;
  2. char grade;
  3.  
  4. // read in total score
  5.  
  6. cout << endl;
  7. cout << "Enter total score (float, must be <= 100): ";
  8. cin >> score;
  9.  
  10. if (score >= 85)
  11. grade = 'A';
  12. else if (score >= 75)
  13. grade = 'B';
  14. else if (score >= 65)
  15. grade = 'C';
  16. else if (score >= 55)
  17. grade = 'D';
  18. else
  19. grade = 'F';
  20.  
  21.  
  22.  
  23.  
  24. // display the result
  25.  
  26. cout << endl;
  27. cout << "Your grade for CMSC 101 is: " << grade << endl;
  28. return (0); // terminate with success
Last edited by chococrack; Oct 22nd, 2008 at 10:55 am.
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Fraction calculator
Next Thread in C++ Forum Timeline: Question on Input with Files





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC