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 favoriteNumber to store the user’s input.

  • Prompts the user with "What's your favorite number?" and reads the value using cin.

  • Uses an if statement to check if the number equals 7; if true, prints "Lucky!"

  • Uses an else if statement to check if the number is even (favoriteNumber % 2 == 0); if true, prints "Even number."

  • If neither condition is true, the else block 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 favoriteNumber to store the user’s input.

  • Prompts the user with "What's your favorite number?" and reads the value using cin.

  • Uses an if statement to check if the number equals 7; if true, prints "Lucky!"

  • Uses an else if statement to check if the number is even (favoriteNumber % 2 == 0); if true, prints "Even number."

  • If neither condition is true, the else block runs and prints "Interesting choice!"

  • Ends with return 0; to signal successful program completion.