Write a C++ program that gives the letter grade for a 5 point quiz..

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..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 #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;

}
closed account (jwkNwA7f)
You didn't put the } to close the switch.

It should be:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 #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;

}


Hope this helped!
Last edited on
Also you didn't #include anything
You should #include <iostream> instead.

You also require a using namespace 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)
Last edited on
closed account (Dy7SLyTq)
and it should be int main
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..

#include <iostream>
using namespace std;

int 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;

}
closed account (jwkNwA7f)
Is it a compiler error that keeps you from creating the .exe?
I think so. I'm using the 2008 Express Edition of Visual C++, and it says that the code is out of date, and that there were build errors..
if using Visual Studio, then

 
#include "stdafx.h" // this is on top of <iostream> 
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..
Why don't you tell us what the errors are? We can probably help you figure them out.
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.

-Incline
Topic archived. No new replies allowed.