I'm up to finish an assignment for my C++, but there must be some thing wrong with the codes....
hope someone will able to give me a hand~
so...here's the title assignment:
Program generates a random math problem, dealing with the : addition, subtraction, multiplication, or division of integer values.
The value ranges for the operand are:
operand 1 operand 2
addition 101-200 101-200
subtraction 101-200 101-200
multiplication 11-20 11-20
division 101-200 11-20
The program randomly picks the operator type and operand values,displays the question, waits for the user to input an answer, then then either tells the user they got the answer correct (if they did) or asks them if they wish to see the correct answer (to which they can respond Y or N for yes or no) if they do wish to see the correct answer the program should display both the original problem and the answer the program should then exit!
And here are my codes: (although its just half done....)
include<iostream>
include<cstdlib>
include<ctime>
using namespace std;
int main ()
{
srand(time (0));
const int PLUS=0; //const PLUS as 0
const int MINUS=1; //const MINUS as 1
const int DIVIDE=2; //const DIVIDE as 2
const int MULTIPLY=3; //const MULTIPLY as 3
int a, b, op;
a = rand() % 200 + 101; //range 101-200
b = (rand() % 200) + 101; //range 101-200
op = rand() % 4; //the 0-3 to match an operation
int answer, userGuess; //right answer
switch(op)
{
case PLUS:
answer = a + b;
cout << "What is " << a << " + " << b << "? ";
cin >> userGuess;
break;
case MINUS:
answer = a - b;
cout << "What is " << a << " - " << b << "? ";
cin >> userGuess;
break;
case DIVIDE:
answer = a / b;
cout << "what is " << a << " / " << b << "? ";
cin >> userGuess;
break;
case MULTIPLY:
answer = a * b;
cout << "what is " << a << " * " << b << "? ";
cin >> userGuess;
}
if(answer == userGuess)
cout << "you are correct." << endl;
return;
}
sorry I'm a noob...but :'(please help me out if you are there. THX