C++ Math Crisis! :x

Hey everyone, umm I got a problem with this C++ program I'm writing.
The objective of the program is to ask the user which level he wants (1 or 2) and give him math problems accordingly... the problems are randomly selected and the sentences like Good job, bravo! , or try again etc... are randmoly selected as well. I wrote the whole program and I'm pretty sure I wrote it correctly but when compiling its giving me several errors like Lvalue Required etc...

if anybody could compile the program and fix it or show me how to fix it I'd be very grateful...

NOTE: I know the program can be done a lot easier through several methods but unfortunately our programming professor wants it this way, no arrays no pointers no linked lists and no strings :/

here is the code :

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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>


int A,B,gcd,flag,level,answer;
int a,b,c,d,e,f,g;
int x,y,N,M,bla,bli,result;


void hmulti(int, int);

void hdivision(int, int);

int hGCD(int, int);

int hcorrect();

int hwrong();






main(){

 int k,num,denom;


do{
  k = 0;
  cout << "Hello there! Welcome" << endl;

  cout << "\n";

  cout << "Please input your level: ";
  cin >> level;
   if(level < 0 || level > 2){
    cout << "Thank you and goodbye!";
    getch();
    return 0;
   }

  if(level == 1){
    do{
     flag = 0;
      g = rand()%2;

       switch(g){
        case 1:
         hmulti(e,f);
         break;

        case 2:
         hdivision(e,f);
         break;
       }

      cout << "Try another question? 1 (for yes) or 2 (for no) :";
      cin >> flag;

    }while(flag == 1);

    if (flag == 0)
     cout << "Thank You, and good bye!" << endl;

  }

  else if(level == 2){
   do{
    flag = 0;
     randomize();
     a=rand()%12 +1;
     b=rand()%12 +1;
     c=rand()%12 +1;
     d=rand()%12 +1;

     randomize();
     int random =rand()%3;

     gcd =(int) hGCD(b,d);

     A = (gcd*a)/b;
     B = (gcd*c)/d;

       switch(random){
        case 1:
         result = a +b;
         break;
        case 2:
         result = a - b;
         break;
        case 3:
         A = a*c;
         B = b*d;
         break;
        case 4:
         A = a*d;
         B = b*c;
         break;
       }

     if(random == 1){

      cout << "What is the value of " << a << "/" << b << " + " << c << "/" << d << " in its simplest form ? ";
      cin >> num >> denom;

       if(num == result && denom == gcd)
        hcorrect();
       else
        hwrong();
     }

     else if (random == 2){

		cout << "What is the value of " << a << "/" << b << " - " << c << "/" << d << " in its simplest form ? ";
      cin >> num >> denom;

       if(num == result && denom == gcd)
        hcorrect();
       else
        hwrong();
     }

     else if(random == 3){


    	cout << "What is the value of " << a << "/" << b << " * " << c << "/" << d << " in its simplest form ? ";
      cin >> num >> denom;

       if(num == result && denom == gcd)
        hcorrect();
       else
        hwrong();
     }

     else if(random == 4){

      cout << "What is the value of" << a << "/" << b << " / " << c << "/" << d << " in its simplest form ?";
      cin >> num >> denom;

       if(num == result && denom == gcd)
        hcorrect();
       else
        hwrong();
     }
  }while( flag ==1);

  if (flag == 0)
   cout << "Thank you, and goodbye!" << endl;

 }while(k = 0);

 getch();
 return 0;
}


/************************************************************************/


void hmulti(int a,int b){

  int answer,c,d,hi;

	 randomize();
    a = rand()%9;
    b = rand()%9;

     cout << "How much is " << a << " times " << b << "?" ;
     cin >> answer;

     if(answer == a*b)
      hcorrect();

     else
	   hwrong();
}

/************************************************************************/

void hdivision(int d,int n){
  int answer,remainder,a,b;

    randomize();
    d=rand()%9;
    n=rand()%100;

     cout << "How many times does " << d << " go into " << n << "?" ;
     cin >> answer >> remainder;

      if(answer == n/d)
       hcorrect();

      else if(answer != n/d)
	    hwrong();

}

/************************************************************************/

int hGCD(int N, int D){

  int z = N % D;
  while(z != 0){

    N = D;
    D = z;
    z = N % D;
  }
  return D;
}



/************************************************************************/


hcorrect(){

  randomize();
  c =1 + rand()%4;
 switch(c){
  case 1:
   cout << "Very Nice!" << endl;
   break;

  case 2:
   cout << "Nice work! " << endl;
   break;

  case 3:
   cout << "Keep up the good work" << endl;
   break;

  case 4:
   cout << "Excellent!" << endl;
   break;
  }
}

hwrong(){

  randomize();
  c =1 + rand()%4;

 switch(c){
  case 1:
   cout << "No.Please try again" << endl;
   break;

  case 2:
   cout << "Wrong, try once more" << endl;
   break;

  case 3:
   cout << "Not quiet, Keep trying!" << endl;
   break;
 }
}
I'll give you a few but you'll have to figure out the rest. First you main doesn't haev a return value. That is an error with my compiler (vc++ express 2008). hwrong and hcorrect also don't have return values.

My compiler couldn't even find <iostream.h>. You need to be using <iostream> instead. Also, specify std::cout rather than just cout. Also use <cstdlib> instead of <stdlib.h>. If you have been studying this website you'd know that those other headers are old and deprecated.

Honestly, there are really a lot of basic errors with this program. I'm not going to type out the whole laundry list. I think you should be able to figure out many of them simply by going to the line number of the error and studying what you wrote.
Considering the way you've layed out your code. Under #include <math.h> you may as well use:
using namespace std;
That will make it so you don't have to use - std:: before cout, cin, endl etc
hwrong and hcorrect have couts in them how do I return values when I'm making cout "sentences" :x
Topic archived. No new replies allowed.