Re: Simple IF statement prog/dos ENTER interaction
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 02/15/04
- Previous message: Chris \( Val \): "Re: Simple IF statement prog/dos ENTER interaction"
- In reply to: Chris \( Val \): "Re: Simple IF statement prog/dos ENTER interaction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 15 Feb 2004 19:01:45 +1100
"Chris ( Val )" <chrisval@bigpond.com.au> wrote in message
news:c0n8e3$17psf9$1@ID-110726.news.uni-berlin.de...
|
| int x;
| cout<< " Enter a number greater than 20 :";
| cin>> x;
| {
| if (x < 20)
| cout<< "Thank you";
| else
| cout<<"Great job ";
| }
|
| {
| if (x > 20)
| cout << "Thank you again";
| else
| cout<< "Your really not so bad";
[snip]
Btw - There is no need to introduce new scopes for your
'if' statements, and you will probably get into trouble
early on in your learning by introducing these.
I would recommend that you play around with 'else if'
statements as well as 'if', which can help you reduce
having to include multiple if statements to evaluate
user input.
For example:
if( x < 20 )
cout<< "Thank you";
else if( x > 20 )
cout<<"Great job ";
else
cout << "You entered 20 ";
Additionally, the identifier 'x' is ok for toy programs
like this, but you should get into the habit of using
meaningful identifier names to make your code easier to
understand - initialising your variables is also recommended
in most cases.
Cheers.
Chris Val
- Previous message: Chris \( Val \): "Re: Simple IF statement prog/dos ENTER interaction"
- In reply to: Chris \( Val \): "Re: Simple IF statement prog/dos ENTER interaction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|