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 :(
3 Antworten
+ 4
This works:
if (age >= 70) {
cout << "You are aged";
}
else {
cout << "You are not that aged";
}
// Remember, every `{` must have a matching `}`.
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";
}
0
I think that the correct code is :
if (age >= 70) {
cout << "You are aged";
}
else {
cout<< "You are not aged";
}
return 0;
}