Hey everyone,
Just started really getting into C++ and i need a bit of help with a code:
The program allows you to answer 3 math problems, but when I add the fourth, it skips over it. Any help is appreciated.Code:#include <iostream> #include <stdlib.h> #include <string.h> #define lastQuestion 4 const int addition = 1; const int subtraction = 2; const int multiply = 3; const int division = 4; void askQuestion(int one, int two, int three, int x) { int answer, input; switch (x) { case addition: answer = one + two; cout << one << " + " << two << " = "; break; case subtraction: answer = one - two; cout << one << " - " << two << " = "; break; case multiply: answer = one * two; cout << one << " * " << two << " = "; break; case division: answer = one / two; cout << one << " / " << two << " = "; break; } cin >> input; if (input == answer) cout << "You are right!" << endl; else cout << "You are wrong, the right answer is " << answer << endl; } int main(int argc, char *argv[]) { int one[lastQuestion], two[lastQuestion],three[lastQuestion], x[lastQuestion]; one[1] = 8; two[1] = 3; x[1] = addition; one[2] = 4; two[2] = 2; x[2] = subtraction; one[3] = -3; two[3] = -3; x[3] = multiply; one[4] = 15; two[2] = 5; x[2] = subtraction; for(int i = 1; i <= lastQuestion; i++) askQuestion(one[i], two[i], three[i], x[i]); system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


