Help in C++ project

Hello everyone ,
I need programming help , it's for a class project in c++ , I've spend almost three days to write the code , but still I have some errors and mistakes , so if you could help me in this code , to make the program work , I'll appreciate it .


Program definition :

Write a program that helps elementary students learn multiplication , addition , division and subtraction . Use rand to produce two positive one-digit integers .it should type question such as :

how much is 6 times 7 ?
Or how much is 4 divided by 2 ?
Or how much is 5 minus 3 ?
Or how much is 6 + 1 ?

( Different questions with different operators )

The student then type the answer . Your program checks the students answer. If its correct , print " very good " then asks another problem - make the program asks10 different math problems -
If the answer is wrong print " no please try again " , then let the student try the same question repeatedly until the student finally gets right.


Here is what I get so far :

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


#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std ;
void menu (int& replay);
bool isCorrect (int& studentAnswer , int answer);
void addition (int num1 , int num2 , char op);
void subtraction  (int num1 , int num2, char op);
void multiplication  (int num1 , int num2, char op);
void division (int num1 , int num2, char op);
 
int main ()
{
int  choice , n1 , n2 ;
int op = rand()%4;
char operatorChar;
srand(time(NULL));
n1 = ((rand() % 10) +1);
n2 = ((rand() % 10) +1);
menu (choice);
for(int i=0; i<10; i++)
// Repeat the questions 10 times
{
do
{
switch(op)
{
case 0:
   operatorChar = '-';
subtraction ( n1 , n2 , operatorChar);
   break;
case 1:
   operatorChar = '+';
addition ( n1 , n2 , operatorChar);
   break;
case 2:
   operatorChar = '*';
multiplication ( n1 , n2 , operatorChar);
   break;
case 3:
   operatorChar = '/';
division ( n1 , n2 , operatorChar);
   break;
}
} while (choice!=2) ;
}
cout << " The End Of The Program ." <<endl;
return 0;
}
 
void menu (int& replay)

{
cout << "Welcome To The easiest Math Tutor!" << endl << endl;
cout << "This simple program designed to help you practice ," << endl;
cout << "addition, subtraction, multiplication, and division" << endl << endl;
cout << "To start:" << endl << endl;
cout << "Please enter 1 , to Quit enter 2 : " << endl;
cout << "\t\t\t\t\t";
cin >> replay;
}
 
bool isCorrect (int& studentAnswer , int answer)
{
return studentAnswer == answer;
}
 
void addition (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
 
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
 
answer=num1+num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout <<"​No, please try again !"<<endl;
cin >> answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;

}
 
void subtraction (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
 
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
 
answer=num1-num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}
 
void multiplication (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1 = ((rand() % 10) +1);
num2 = ((rand() % 10) +1);
 
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
 
answer=num1*num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if (isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}​​​​​​​​​​
 
void division (int num1 , int num2 , char op)
{
int studentAnswer, answer;
srand(time (0));
num1= ((rand() % 10) +1);
num2= ((rand() % 10) +1);
 
cout << "How much is" << " "<< num1 <<" " << operatorChar << " "<< num2 << "?" << endl;
cin >> studentAnswer;
 
answer = num1 / num2;
do
{
cin>> studentAnswer;
if (studentAnswer != answer)
cout<< "No, please try again !" <<endl;
cin << answer;
} while (studentAnswer != answer);
if(isCorrect(studentAanswer , Answer)
cout<< "Very Good !" <<endl;
}​
   


Thank you in advance .
Last edited on
1. you have not defined 'choice' on line 21.
2. you dont need to pass by reference on most of your methods that take an int or char.
3.
void addition (int num1 , int num2 , char& operator );

the word operator is a reserved keyword so use a different variable name

4. you've spelt 'multiplication' wrong on line 39.

5.
cout<< “​No, please try again !” <<endl;
you aren't using the correct quotation marks for a lot of your strings.

6. more stuff, but that should be enough for now.


Your compiler should have told you the same kind of stuff though?

edit: there's no way you could have compiled this..
Last edited on
Thank you 4 your replay ,,,
I appreciate your help ,,,
I fix them ,,,
But still there are some errors -_-'
your compiler should tell you where and what they are.
Topic archived. No new replies allowed.