Solution: Add a Joke Option

This program displays a simple interactive menu where users can choose actions like saying hello, showing info, hearing a random joke, or exiting.

Line-by-line breakdown:

  • Runs a loop that repeatedly shows the main menu until the user selects “Exit.”

  • Takes user input to choose between options.

  • Uses a switch statement to perform actions based on the user’s choice.

  • Option 1 prints a friendly greeting.

  • Option 2 displays program information.

  • Option 3 exits the loop and ends the program.

  • Option 4 randomly selects and displays a joke from a small list using a random number generator.

  • Handles invalid inputs by showing an error message.

Solution: Add a Joke Option

This program displays a simple interactive menu where users can choose actions like saying hello, showing info, hearing a random joke, or exiting.

Line-by-line breakdown:

  • Runs a loop that repeatedly shows the main menu until the user selects “Exit.”

  • Takes user input to choose between options.

  • Uses a switch statement to perform actions based on the user’s choice.

  • Option 1 prints a friendly greeting.

  • Option 2 displays program information.

  • Option 3 exits the loop and ends the program.

  • Option 4 randomly selects and displays a joke from a small list using a random number generator.

  • Handles invalid inputs by showing an error message.