+ 2

Getting "unqualified id before else statement" error in line 19

#include <iostream> using namespace std; int main() { int age; cin>>age; if (age >12) { if(age >= 18) {if (age < 130) { cout << "Adult"; }} else { if (age>=130) { cout<< "vampire";} }} else { cout << "Teenager"; } } else { if (age > 0) { cout << "Child"; } else { cout << "alien"; } } return 0; } error in line 19 plz help & explain

12th Nov 2016, 6:57 AM
Amandeep Singh
Amandeep Singh - avatar
4 Antworten
+ 1
close else why you use so many if
12th Nov 2016, 7:10 AM
DeleteMe
+ 1
just copied it from module and modified it 😅. which loop should I use to shorten the code ? I don't have much knowledge of coding I am mechanical engineer 😥
12th Nov 2016, 7:13 AM
Amandeep Singh
Amandeep Singh - avatar
+ 1
#include <iostream> using namespace std; int main() { int age; cin>>age; if (age>18) {cout .....} if (age==18) {cout....} if (age<18) { .... } return 0; } change [...] whatever you want to do if condition is true you can and more too
12th Nov 2016, 7:25 AM
DeleteMe
+ 1
#include <iostream> using namespace std; int main() { int age; cout<<"This person is "; cin>>age; { if (age >0) { if(age >= 18) {if (age < 130) { cout << "an Adult"; } else { if (age>=130) {if (age<2000) cout<< "a vampire!!";} }} else {if (age<18){if (age>12) {cout << "a Teenager"; }}} } if (age<=12) { cout << "a Child"; } else {if (age>=2000) cout << "yo mama!!"; } } return 0; } finally running code!! most error were bcoz of extra } at end of program
12th Nov 2016, 7:50 AM
Amandeep Singh
Amandeep Singh - avatar