When an if-else
statement is executed in the body of another if-else
statement, it is called nested.
Line | Description |
---|---|
5 | Initializes the variable number with the value 61 |
7 | If the value of number is less than or equal to 100 |
8 – 9 | If the value of number is less than 50, print the string “Value is smaller than 50” |
10 – 11 | If the value of number is less than 50, print the string “Value is 50” |
12 – 13 | Otherwise the string “Value is between 51 und 100“ is output |
15 – 16 | If the value of number is greater than 100 the following string “Value is greater than 100” is output |
19 | The main function expects a return value of type int -> int main() . Therefore the value 0 is returned |
#include <iostream>
using namespace std;
int main() {
int number = 61;
if (number <= 100) {
if (number < 50) {
cout << "Value is smaller than 50";
} else if (number == 50) {
cout << "Value is 50";
} else {
cout << "Value is between 51 und 100";
}
} else {
cout << "Value is greater than 100";
}
return 0;
}
Value is between 51 und 100