0

If statements

#include <iostream> using namespace std; int main() { int age; cout << "W E L C O M E\n"; cout<<"Please enter your age\n"; cin >> age; if (age >= 70) { cout << "You are aged"; else (age<70){ cout<< "You are aged"; } } return 0; } Why won't this work ? I'm really confuse about how these curly brackets work :(

21st Aug 2018, 8:00 PM
harry
3 Respuestas
+ 4
This works: if (age >= 70) { cout << "You are aged"; } else { cout << "You are not that aged"; } // Remember, every `{` must have a matching `}`.
21st Aug 2018, 8:05 PM
Eduardo Petry
Eduardo Petry - avatar
0
It looks like you tried to chain the if statements which are multiple else ifs not just else but there's no point in adding the second condition as just an else statement would do the same job (as long as it's an integer) e.g. if (age >= 70) { cout << "70+"; } else { cout << "<70"; }
21st Aug 2018, 8:08 PM
TurtleShell
TurtleShell - avatar
0
I think that the correct code is : if (age >= 70) { cout << "You are aged"; } else { cout<< "You are not aged"; } return 0; }
21st Aug 2018, 10:29 PM
Lucas
Lucas - avatar