Hello everyone!
I've been working on some basic code which is supposed to have multiple ( simple to start with) math problems that must be answered, and depending on the answer, will tell you either to try again, or "Good job!" if you answered correctly.
This is just something I started to work on to help teach me about if statements, the preprocessor, and a few other features I hope to add to this program eventually.
The problem is in the if statement; in line 18. I have no idea what to put in the if statement "a < 9", 9 has to be replaced with a variable, but when I do, I get compiling errors, which I've searched for an answer, but it didn't fit my situation enough to understand.
The idea is to be able to change the numbers in the preprocessor, without having to edit the if statements as well, that's why I believe I need variable.
Thanks in advance for the help!
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
|
#include <iostream>
#include <limits>
#define mp1 "5"
#define mp1a "4"
using namespace std;
int main()
{
cout << mp1 << " + " << mp1a << " = ";
int a;
cin >> a;
if (a < 9)
cout << endl << "Sorry, try again!" << endl;
else if (a > 9)
cout << endl << "Sorry try again!" << endl;
else
cout << endl << "Good job!" << endl;
std::cout << endl << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
}
|