Solution: Favorite Number Message
The main() function takes user input for their name and favorite number, calculates the square of that number, and displays a personalized message.
Declares three variables:
name(string),favoriteNumber(integer), andsquare(integer).Prompts the user with "What's your name?" and stores the input in
name.Prompts the user with "What's your favorite number?" and stores the input in
favoriteNumber.Calculates the square of the number using
favoriteNumber * favoriteNumberand stores it insquare.Uses
coutto print a personalized message showing the user’s name, their number, and its square — for example:
"Hi Jordan, the square of 7 is 49."Ends with
return 0;to indicate successful program completion.
Solution: Favorite Number Message
The main() function takes user input for their name and favorite number, calculates the square of that number, and displays a personalized message.
Declares three variables:
name(string),favoriteNumber(integer), andsquare(integer).Prompts the user with "What's your name?" and stores the input in
name.Prompts the user with "What's your favorite number?" and stores the input in
favoriteNumber.Calculates the square of the number using
favoriteNumber * favoriteNumberand stores it insquare.Uses
coutto print a personalized message showing the user’s name, their number, and its square — for example:
"Hi Jordan, the square of 7 is 49."Ends with
return 0;to indicate successful program completion.