if, else if statements

#include "lesson1.h"


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()

{	
	int age;
	
	cout<< "enter your age; ";
	cin >> age;
	cin.ignore();
	
	
	if (age <100) {
		cout<< "true\n";
	}
	else if (age>100) {
		cout<< "false\n";
	}
	
	else if (age == 100); {
		 cout<<"unknown\n";
	 }
	
	cin.get();
	
}


 When the either the 'if' or the first 'else if' statement is parsed
 the output indicates the second 'else if' statement is also parsed 
and the output is shown as 'true / unknown'  or ' false / unknown'
 I don't understand why the second 'else if' statement is also parsed 
when the user input simply meets the 'if' or the first 'else if' 
requirement.
Last edited on
You have an extra ';' after your age == 100 else if.
1
2
3
else if (age == 100); {
		 cout<<"unknown\n";
	 }


You have a semi colon at the end of your else if. Remove it.

EDIT: Too slow
Last edited on
You have an extra ';' after your age == 100 else if.
Sorry for all the edits, but I did not want to flamed. any how thanks -- silly me:-)
Topic archived. No new replies allowed.