Solution: Number-Based Response
The main() function takes the user’s favorite number as input and uses conditional statements to print a response based on the number’s value or type.
Declares an integer variable
favoriteNumberto store the user’s input.Prompts the user with "What's your favorite number?" and reads the value using
cin.Uses an
ifstatement to check if the number equals7; if true, prints "Lucky!"Uses an
else ifstatement to check if the number is even (favoriteNumber % 2 == 0); if true, prints "Even number."If neither condition is true, the
elseblock runs and prints "Interesting choice!"Ends with
return 0;to signal successful program completion.
Solution: Number-Based Response
The main() function takes the user’s favorite number as input and uses conditional statements to print a response based on the number’s value or type.
Declares an integer variable
favoriteNumberto store the user’s input.Prompts the user with "What's your favorite number?" and reads the value using
cin.Uses an
ifstatement to check if the number equals7; if true, prints "Lucky!"Uses an
else ifstatement to check if the number is even (favoriteNumber % 2 == 0); if true, prints "Even number."If neither condition is true, the
elseblock runs and prints "Interesting choice!"Ends with
return 0;to signal successful program completion.