# Problem with Boolean.

• 02-03-2005
Asbestos
Problem with Boolean.
Okay, well, I copied the script from the tutorial on the site (the enter your age tutorial one), and I added more phrases. The problem was that if you entered, "2", as your age, you would get all the answers for the other ages. Let me post the code so you know my problem.
Code:

```#include <iostream>    using namespace std;         int main() {   int age;     cout<<"Please input your age: ";   cin>> age;   cin.ignore();   if ( age <= 25 ) {     cout<<"You are pretty young!\n";   }   if ( age <= 50 ) {     cout<<"You are middle aged\n";   }   if ( age <= 100 ) {       cout<<"You are old\n";   }   else if ( age <= 125 ) {     cout<<"You are really old\n";   }   else {       cout<<"Stop lying you moron and tell me your age\n";   }   cin.get(); }```

That was what I originally changed, until this...

Code:

``` #include <iostream>    using namespace std;         int main() {   int age;     cout<<"Please input your age: ";   cin>> age;   cin.ignore();   if ( age <= 25 ) {     cout<<"You are pretty young!\n";   }   if ( age <= 50 && >= 26 ) {     cout<<"You are middle aged\n";   }   if ( age <= 100 && >= 51 ) {       cout<<"You are old\n";   }   else if ( age <= 125 && >= 101 ) {     cout<<"You are really old\n";   }   else {       cout<<"Stop lying you moron and tell me your age\n";   }   cin.get(); }```
The problem is I don't know boolean, or how to fix this problem so please help me, a lonely n00b, out.
• 02-03-2005
pianorain
Code:

`  if ( age <= 50 && age >= 26 ) {`
You're pretty close; just add age to each check.
• 02-03-2005
Asbestos
Oh dude, thanks. Now let me try it out.

EDIT: Awesome, it works. Thanks man.
• 02-03-2005
hk_mp5kpdw
Either that or you are missing a couple else's:

Code:

```#include <iostream>    using namespace std;         int main() {   int age;     cout<<"Please input your age: ";   cin>> age;   cin.ignore();   if ( age <= 25 ) {     cout<<"You are pretty young!\n";   }   else if ( age <= 50 ) {     cout<<"You are middle aged\n";   }   else if ( age <= 100 ) {       cout<<"You are old\n";   }   else if ( age <= 125 ) {     cout<<"You are really old\n";   }   else {       cout<<"Stop lying you moron and tell me your age\n";   }   cin.get(); }```
• 02-03-2005
Asbestos
Oh yeah, thanks dude. Also, how would I make it say random things? Well, not random, but randomly pick a phrase for that specific input. So like, if they say a number from 50 to 100, it'll pick a phrase that's meant to be said only for 50 to 100.
• 02-03-2005
hk_mp5kpdw
Quote:

Originally Posted by Asbestos
Also, how would I make it say random things? Well, not random, but randomly pick a phrase for that specific input. So like, if they say a number from 50 to 100, it'll pick a phrase that's meant to be said only for 50 to 100.

You would need an array or other somesuch container which held the strings that you wished to select from. Then you would need to use the srand and rand functions to generate a random number from which you would be able to pick one of the strings to output.
• 02-03-2005
Asbestos
Oh thanks. Now let me ask my god google for some tuts on that :D .
• 02-03-2005
fuh
Quote:

Originally Posted by Asbestos
Oh thanks. Now let me ask my god google for some tuts on that :D .

Or you could just look at the tutorial. The main Cprogramming website is available to look at and learn from.
• 02-03-2005
Asbestos
How did I miss that? Oh well, thanks.
• 02-03-2005
fuh
You're welcome!

Sorry if I sounded grumpy. I was in a bad mood, but then I played with my Hello Kitty dolls... I...I mean ate a bowl of ice cream, yeah, that was it!

\/\/
fuh
/\/\
• 02-03-2005
Asbestos
No offense taken, and Hello Kitt... Ice Cream is the best thing ever made. Yes, ice cream.
• 02-03-2005
Zach L.
"Hello Kitty"? :confused:

*edit*
Hmm... Rather peculiar. :)