If Statement - Using Two Numbers

Hi,

I just began learning to code C++ the other day, so bear with me.

I was trying to make a simple program where you enter your name and age and it repeats it back to you and asks your if the information you entered was correct.

What I'm trying to make is a line of code the tells the user that they entered and invalid number is they try to input anything other than 1 or 2.

You get to a point where it asks you to press 1 if the info is correct, and 2 if it isn't. The only problem is, when trying to make an if statement, it doesn't work. Here is what I did:
**
if(status != 1 or 2){
cout << "Value entered not valid. Type 1 if information is correct and 2 if it is not."<<endl;
}
**
What it does is it gives the error message even if I type one or two.

Thanks in advance for the help.
Last edited on
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
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

const int YES = 1;
const int NO = 2;


int main ()
{
  string name;
  cout << "Enter your name: ";
  cin >> name;
  cout << "\nEnter your age: ";
  int age;
  cin >> age;
  cout << "Name = " << name << " Age = " << age;
  
  cout << "\nIs this correct? (yes = 1, no = 2) ";

  int answer = 0;
  cin >> answer;
  if (answer == YES)
    cout << "\nCorrect\n\n";
  else if (answer == NO)
    cout << "\nNot correct\n\n";
  else
    cout << "\nInvalid choice\n\n";

  system ("pause");
  return EXIT_SUCCESS;
}
Thanks a lot :)
Topic archived. No new replies allowed.