checking age

im working on a program that asks for age

and outputs the age but what i want it to check is if the user entered 0 or 100 i want it to output your kidding this is what i got ... but no matter what # i enter it still displays "your kidding"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
using namespace std;


int main()
{
	int age;

	cout << "What is your age" <<endl;
	cin >> age;
	cout <<"I hear you just had a birthday and are: " << age <<endl;

	if(age == 0 || 100)true;
	{
		cout << "Your Kidding" <<endl;
	}	

	
}
Last edited on
I had the same problem when I first learned OR operators, you have to type this:

 
if(age == 0 || age == 100)true


Instead of this:
 
if(age == 0 || 100)true


You should use the ELSE statement also so that it doesn't print out both statements:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <string>
using namespace std;


int main()
{
	int age;

	cout << "What is your age" <<endl;
	cin >> age;
	if (age == 0 || age == 100)
	{
	cout << "Your kidding" << endl;
	}
	else
	cout <<"I hear you just had a birthday and are: " << age <<endl;
	
	system ("PAUSE");
	
}

Last edited on
thanks man it works seemlessly
No problem glad I could help
Topic archived. No new replies allowed.