Adding correct and incorrect counter code???

Below is the Question given to me... and i'm having problem in my coding please help me..

Develop an application that creates a mathematical quiz to the primary school level. The quiz should contain 5 questions from the selected arithmetic operation (prompt user to select a topic):
Addition +
Subtraction -
Multiplication *
Division /

The questions should randomly display number of operand between 1 up to 20 only. Example of question shown below:
...................................................
Assumed that the student choose “Addition” topic:
Question 1:
2 + 13 = ?
Question 2:
16 + 20 = ?
Question 3 :
1 + 17 = ?
....................................................
When the user answers the question correctly, display a congratulatory message. If the user responds to a question incorrectly, display an appropriate message as well as the correct answer. At the end of the quiz, display the number of correct and incorrect answers, and the percentage of correct answers.

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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

void add()
{
int result=0;
int correctcounter=0;
int incorrectcounter=0;

int A = rand()%20+1;
int B = rand()%20+1;

cout<<A<<" + "<<B<<" = ?"<<endl;
cout<< "Answer : ";
cin>>result;
cout<<endl<<endl;

if(result == A+B){
correctcounter++;
cout<<" CORRECT!! Well done!! "<<endl<<endl;

}
if(result !=A+B){
incorrectcounter++;
cout<<" WRONG!the answer is "<<A+B<<endl<<endl;
}

}

void subtract()
{
int result=0;
int correctcounter=0;
int incorrectcounter=0;

int A = rand()%20+1;
int B = rand()%20+1;

cout<<A<<" - "<<B<<" = ?";
cout<< "Answer : ";
cin>>result;
cout<<endl<<endl;

if(result == A-B){
correctcounter++;
cout<<" CORRECT!! Well done!! "<<endl<<endl;

}
if(result !=A-B){
incorrectcounter++;
cout<<" WRONG!the answer is "<<A-B<<endl<<endl;
}

}

void multiply()
{
int result=0;
int correctcounter=0;
int incorrectcounter=0;

int A = rand()%20+1;
int B = rand()%20+1;

cout<<A<<" * "<<B<<" = ?";
cout<< "Answer : ";
cin>>result;
cout<<endl<<endl;

if(result == A*B){
correctcounter++;
cout<<" CORRECT!! Well done!! "<<endl<<endl;

}
if(result !=A*B){
incorrectcounter++;
cout<<" WRONG!the answer is "<<A*B<<endl<<endl;
}

}

void divide()
{
int result=0;
int correctcounter=0;
int incorrectcounter=0;

int A = rand()%20+1;
int B = rand()%20+1;

cout<<A<<" / "<<B<<" = ?";
cout<< "Answer : ";
cin>>result;

if(result == A/B){
correctcounter++;
cout<<" CORRECT!! Well done!! "<<endl<<endl;

}
if(result !=A/B){
incorrectcounter++;
cout<<" WRONG!the answer is "<<A/B<<endl<<endl;
}
}

int main()
{
    int Selection;
    
     cout << "Select a topic"<<endl;
     cout <<endl;  
          cout << "1.Addition"<<endl;
          cout << "2.Subtraction"<<endl;   
          cout << "3.Multiplication"<<endl;
          cout << "4.Division"<<endl<<endl;
          cout << "Topic No. : ";
     cin >> Selection;
     
     system("cls");
    
    switch(Selection){		//	Switchcase on said number
		case 1:
        for(int i=1;i<=5;i++) 
        {  
	    	add();	//	If 1; addition
			break;
        }
		case 2:
        for(int i=1;i<=5;i++) 
        {  
			subtract(); //	If 2; subtraction
			break;
        }
		case 3:
        for(int i=1;i<=5;i++) 
        {  
			multiply(); //	If 3; multiplication
		break;
        }

		case 4:
        for(int i=1;i<=5;i++) 
        {  
			divide(); //	If 4; division
		break;
        }
		
        default:
			cout << "ERROR: Input not an integral value from 1-3" << endl;	// Standard output - shouldn't get printed
      	}
	return 0;

    system("PAUSE");
    return EXIT_SUCCESS;
}



1. how should i edit the code so that each topic gives me 5 question.. currently if i choose addition it only provide 1 question and goes to subtraction.

2.please guide me on how to add the correct and incorrect counter please..

please help me.. thanking you in advance...
Last edited on
try changing your code to
1
2
3
4
5
6
7
8
	
case 1:
        for(int i=1;i<=5;i++) 
        {  
	    	add();	//	If 1; addition
			
        }
break;
A doublepost of: http://www.cplusplus.com/forum/general/140496/

Tip: You should be able to move existing thread to different Forum by editing the first post.
Topic archived. No new replies allowed.