I'm new to C++ and struggling to grasp a lot of the basic concepts. I've been given an assignment to "write a C++ program that gives the letter grade for a 5 point quiz. Have the program prompt the user to enter 0-5 and then have it output a letter grade.(Must use switch statement)." This is the code I've come up with, but I can't seem to make it work. Any help would be greatly appreciated. Thanks in advance..
#include
void main()
{
int grade;
cout<<"enter score \n";
cin>>grade;
switch(grade)
{
case 0:
cout<<"Grade is F";
break;
case 1:
cout<<"Grade is E";
break;
case 2:
cout<<"Grade is D";
break;
case 3:
cout<<"Grade is C";
break;
case 4:
cout<<"Grade is B";
break;
case 5:
cout<<"Grade is A";
break;
return 0;
}
#include
void main()
{
int grade;
cout<<"enter score \n";
cin>>grade;
switch(grade)
{
case 0:
cout<<"Grade is F";
break;
case 1:
cout<<"Grade is E";
break;
case 2:
cout<<"Grade is D";
break;
case 3:
cout<<"Grade is C";
break;
case 4:
cout<<"Grade is B";
break;
case 5:
cout<<"Grade is A";
break;
} // The if statement was never closed
return 0;
}
Also you didn't #include anything
You should #include <iostream> instead.
You also require a usingnamespace std; after the #include line.
Another thing:
void main() should never be used.
Change it into int main().
(You're also returning 0 from a void function, which leads to a compilation error: A void function cannot return a number. Only a number function can return a number)
Thanks for the help, guys. I don't know how I managed to forget those basic rules. After the changes I made, I still can't get the code to work. Not sure what I'm doing wrong..
Hmm. That doesn't fix it. I guess I'll just have to keep messing around with the code before I submit my assignment in. Thanks for the help guys. I really appreciate it..
Stdafx is for other kind of projects.
Don't add it manually.
Just tell us which kind of errors are those, and write the lines of codes where the errors should be.
E.G.:
Error "invalid token" on line 5123.
Line 5123 contains "kebab&$! = 4;"
Also, you may want to work on the format of your code. It's kind of all wibbly-wobbly and not organized. Try using indentation and cleaning it up a bit. Code is no good if it's difficult to read.