Help with code please

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 10
Reputation: dtaylor01 is an unknown quantity at this point 
Solved Threads: 0
dtaylor01 dtaylor01 is offline Offline
Newbie Poster

Help with code please

 
0
  #1
Oct 21st, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,500
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1479
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Help with code please

 
0
  #2
Oct 21st, 2008
C and C++ do not have "END IF" statements.
  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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 429
Reputation: Denniz is on a distinguished road 
Solved Threads: 15
Denniz's Avatar
Denniz Denniz is offline Offline
Posting Pro in Training

Re: Help with code please

 
1
  #3
Oct 22nd, 2008
Take away all those semi-colons after the if and else-if statement:

  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';
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 114
Reputation: sidatra79 is an unknown quantity at this point 
Solved Threads: 8
sidatra79's Avatar
sidatra79 sidatra79 is offline Offline
Junior Poster

Re: Help with code please

 
0
  #4
Oct 22nd, 2008
Originally Posted by dtaylor01 View 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
Start using C++....when posting in the C++ section
"What we repeat defines what we are!!" Aristotle
-->
"looping.. defines Perfomance from O (n) ..up to O(n!)" Sidatra79 :D :D
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Help with code please

 
0
  #5
Oct 22nd, 2008
  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.
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC