Forbids comparison between pointer and integer

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;
}
show us the code that gets you compiling errors..
also..

1
2
3
4
5
6
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;


is equal to...

1
2
3
4
if (a <> 9)
        cout << endl << "Sorry, try again!" << endl;
      else
        cout << endl << "Good job!" << endl;


just a note..
1
2
3
4
      int answer = 9;
      if (a < answer)
        cout << endl << "Sorry, try again!" << endl;
      else if (a > answer)

then just assign new numbers to answer as needed
why do u want to edit the values in the preprocessor?.. You can either do what KOT4K0t4 said or

#define val 9

and not

define val "9"

maybe u got a compiling error there, if u added quotes like here

#define mp1 "5"

and tried to compare it to a
Thank you so much guys!

Both would certainly work, but for some reason taking away the quotes in the preprocessor fixed it, I'm now able to write something like this:

1
2
if (a < mp1 + mp1a)
        cout << endl << "Sorry try again!" << endl;


Why do the double quotations make a difference?

cause its not a number, but a string
I see, guess I need to read up a bit more on the subject.

Thanks for help!
Topic archived. No new replies allowed.