how do a make a program calculate a test grade

how do I make this program calculate the grade average on this fake test I made?
here is the test i made and it all checks out - now I need it to print out the grade made on the test after completion.

how do I do this?

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

#include <iostream>
using namespace std;

int main()
{

char Answer;



cout<<"you will be givin a short Exam of 5 questions \n"<<endl;
cout<<"Press enter after each question is answered \n"<<endl;
cout<<endl;
cout<<endl;
do
{
cout<<"Question 1"<<endl;
cout<<"where was Jason Born? \n\n"<<endl;
cout<<endl;
cout<<"(a) - Chicago?"<<endl;
cout<<"(b) - Atlanta?"<<endl;
cout<<"(c) - Pheonix?"<<endl;
cout<<"(d) - Tucson?" <<endl;
cin>>Answer;

cin.get();

if (Answer=='d')
{
cout<<"Thats Correct!"<<endl;
}
else
cout<<"Try Again"<<endl;
}while (Answer== 'a' || Answer=='b' || Answer=='c');

do
{
cout<<"Question 2"<<endl;
cout<<"Where did Jason go to highschool"<<endl;
cout<<endl;
cout<<"(a) Sahuaro ?"<<endl;
cout<<"(b) Sabino ?"<<endl;
cout<<"(c) Huntsville ?"<<endl;
cout<<"(d) Santa Rita ?"<<endl;
cin>>Answer;

cin.get();

if (Answer=='a')
{
cout<<"Right again!"<<endl;
}else
cout<<"try again"<<endl;
}while (Answer=='b' || Answer=='c' || Answer=='d');

do
{
cout<<"Question 3"<<endl;
cout<<"Where does Jason go to College"<<endl;
cout<<endl;
cout<<"(a) UAH ?"<<endl;
cout<<"(b) UNA ?"<<endl;
cout<<"(c) Alabama A&M ?"<<endl;
cout<<"(d) Athens Sate ?"<<endl;
cin>>Answer;

cin.get();

if (Answer=='c')
{
cout<<"Your on a roll!"<<endl;
}else
cout<<"try again"<<endl;
}while (Answer=='a' || Answer=='b' || Answer=='d');

do
{
cout<<"Question 4"<<endl;
cout<<"what is Jason's Major"<<endl;
cout<<endl;
cout<<"(a) Electrical Engineer ?"<<endl;
cout<<"(b) Civil Engineer ?"<<endl;
cout<<"(c) Computer Science ?"<<endl;
cout<<"(d) Mechanical Engineer ?"<<endl;
cin>>Answer;

cin.get();

if (Answer=='c')
{
cout<<"Yes-4 in a role!"<<endl;
}else
cout<<"try again"<<endl;
}while (Answer=='a' || Answer=='b' || Answer=='d');

do
{
cout<<"Question 5"<<endl;
cout<<"What floor is the computer science office on ?"<<endl;
cout<<endl;
cout<<"(a) 1st floor ?"<<endl;
cout<<"(b) 2nd floor ?"<<endl;
cout<<"(c) 3rd floor ?"<<endl;
cout<<"(d) Basement ?"<<endl;
cin>>Answer;

cin.get();

if (Answer=='c')
{
cout<<"Yes- you have completed this test!"<<endl;
}else
cout<<"try again"<<endl;
}while (Answer=='a' || Answer=='b' || Answer=='d');
return 0;
}
One way you could do it is by having a char for the answer for each question. So an answer1, answer 2, answer 3, answer 4, answer 5. Then have a bunch of if statements at the end like so:

1
2
3
4
if (Answer1=='d' && Answer2=='a' && Answer3=='c' && Answer4=='c' && Answer5=='c')
{
cout<<"Score: 100%"<<endl;
}


This isn't the best option but based off the rest of your code this is probably an easier way for you to understand. You would need an if statement for each possibility.

There are much more simple and efficient ways where you could use loops and such but this is something you can consider.
Well you could give each question an integer value and each loop decrement it by one point. Then at the end, use that to gauge the score.
Start out with 25, then each answer wrong, lose a point. Or Number of questions * 4 (the number of answers);
Topic archived. No new replies allowed.