| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Littel problem
Hey, I'm making for my study my first C++ program and I have a program whitch a if statement.
...... cin >> jaar; if ( (jaar < 1900) || (jaar > 2100) ); { cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n"; return 0; } ..... this is the statement waht is troubling me. When I enter 1987 for the integer the if statement is still activate. I want that the program ignore the if statement when the integer "jaar" is between the value 1900 and 2100. But it doesn't work. Can somebody tell me waht I doing wrong? |
|
#2
|
|||
|
|||
|
Hi,
I didn't quite understand what do you want to say?Please elaborate! Costas |
|
#3
|
|||
|
|||
|
what I wanted to say is,
1. I have a integer called jaar. (dutch word for year but oke )2. when you enter a value for "jaar" that is < 1900 or > 2100 the program will preform cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n"; return 0; But when the value entered for "jaar" is 1900 >= jaar or 2100 <= jaar. the program must ignore the If-statement. But the problem I have that for wahtever value I enter the program runs cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n"; return 0; My question is how can I fix that. |
|
#4
|
|||
|
|||
|
You need an else:
else { cout << "Whatever, here"; } you have your return 0 inside the if statement. Put that at the end of the program, should be the last thing. |
|
#5
|
|||
|
|||
|
cin >> jaar;
if ( (jaar < 1900) || (jaar > 2100) ); { cout << "Dit jaartal is ongeldig. Toegang Geweigerd. \n"; return 1; } else { cout << " "; } when I put a else with a random command my compiler gives the error C2181: illegal else without matching if. What is the problem with that error? |
|
#6
|
|||
|
|||
|
There shouldn't be a ; after the if condition. What the program says is: If jaar < 1900 or jaar > 2100 -- do nothing (since the semicolon's there). Then, cout and return. So take out the semicolon.
|
|
#7
|
|||
|
|||
|
Yes, ubergeek is right; you don't put ; at the end of any condition. Why I didn't see it at first time.
|
|
#8
|
|||
|
|||
|
Yeah, same here, costas -- a very hard error to catch. I didn't see it until I saw the error C2181 above.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Littel problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|