| | |
Help with code please
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 10
Reputation:
Solved Threads: 0
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 C and C++ do not have "END IF" statements.
C++ Syntax (Toggle Plain Text)
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'; // display the result cout << endl; cout << "Your grade for CMSC 101 is: " << grade << endl; 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.
Take away all those semi-colons after the if and else-if statement:
C++ Syntax (Toggle Plain Text)
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';
Founder of :
Lexel Technologies Pte Ltd - SMS (TXT) Marketing software solution
My Blogs: Gooner's Sanctuary
Pet Directory and Forum: FurryTale.net
Lexel Technologies Pte Ltd - SMS (TXT) Marketing software solution
My Blogs: Gooner's Sanctuary
Pet Directory and Forum: FurryTale.net
•
•
•
•
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
"What we repeat defines what we are!!" Aristotle
-->
"looping.. defines Perfomance from O (n) ..up to O(n!)" Sidatra79 :D :D
-->
"looping.. defines Perfomance from O (n) ..up to O(n!)" Sidatra79 :D :D
C++ Syntax (Toggle Plain Text)
int score; char grade; // 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'; // display the result cout << endl; cout << "Your grade for CMSC 101 is: " << grade << endl; 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
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Why won't this code work? (VB.NET)
- Need help with DirectX code (C)
- Tutorials & Code Submissions - Questions? (DaniWeb Community Feedback)
- Some Basic Code Hopefully (Help Needed) (HTML and CSS)
Other Threads in the C++ Forum
- Previous Thread: Fraction calculator
- Next Thread: Question on Input with Files
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






