Control flow
The else statement is a complement to the if statement. It is used like this:
if (condition) {
// Do stuff if condition is true
}
else {
// Do stuff if condition is false
}
It can also be used alongside if statements to check for many conditions, for example:
if (i > 0) {
std::cout << i << " is a positive number." << std::endl;
}
else if (i < 0) {
std::cout << i << " is a negative number." << std::endl;
}
else {
std::cout << i << " is 0." << std::endl;
}
Your task is to write a program using if and else statement to print out the color of the flowers as shown below:
flower | color |
---|---|
rose | red |
violet | blue |
sunflower | yellow |
rose
red