Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Learning Objectives: Use of for loops to solve counter-controlled problems Use of do/while loops for validation and/or menu loops Use of switch statements for multi-way

image text in transcribedimage text in transcribedimage text in transcribed

Learning Objectives: Use of for loops to solve counter-controlled problems Use of do/while loops for validation and/or menu loops Use of switch statements for multi-way decisions General Description: Write a program that allows the user to choose one of three "games" to play. It should repeat the following until the user selects X to exit: Display a menu with the options: S - Sum Between B - Print Box X - Exit Enter option: The user may enter more than one character to choose an option, but the program should ignore all but the first character. The first character may be lower-case, but the program will treat both the same. Use the following code to input a string and get the first char of the string: char opt; string answer; - - cout > answer; opt = answer When the user enters an invalid option, print "Invalid option! Try again!" When the user enters X, print "Thanks for playing", do a system pause, and end the program. When the user enters S: o Ask the user to enter a number to start counting, and a number to stop counting. You may assume the second number will be greater than or equal to the first, and both will be integers. o Calculate the sum of all numbers between and including the start and stop values entered. O Print the sum in a message in the format: The sum of numbers between start and stop is sum. Example: The sum of numbers between 2 and 5 is 14. When the user enters B: o Ask the user to enter the size of a box. You may assume the number is an integer between 1 and 15. O Print a square of stars on the screen using the number entered as the dimension Example: user enters 5, print 5 stars on 5 lines, with a space between each star on a line: Specifications: Use a do/while loop to repeat the overall menu process Use a switch statement to select the game to play or exit. Make the game menu accept both upper and lower case letters, without using any sort of upper case" function (hint: 2 cases). Use a for loop to solve the sum between problem - Use nested for loops to print the box. Sample Execution: S - Sun Between B - Box - exit Enter option: addemup Invalid option! Try again! S - Sun Between B - Box X - exit Enter option drawbox Invalid option! Try again! - Sun Between B-Box X-exit Enter option: S Enter start and stop nunbers: 25 Sun of numbers between 2 and 5 is 14 S - Sun Between - Box 8 = rWit Enter options b Enterslae of box: 5 Thanks for playing! S - Sun Between B - Box X - exit Enter option: X Thanks for playing Press any key to continue . Rubrics: comment box at top with Lab 3 and Student Name Prints the menu as shown in the example and asks the user to enter an option. Accepts any string of characters (with no spaces), but bases its reaction only on the first character of the string entered. Treats: b/B, S/S and x/x the same (not case sensitive) Game menu repeats until x or X (or XRay) is entered. When an invalid option is entered, gives an error message When Sentered o asks for begin and end number o prints a message with the begin, end and sum as shown in the example. When B entered: o asks the user to enter the size of the box. O prints a square box of the entered size, each star followed by a space. Prints "Thanks for playing on exit. System Pause at the end Uses a do/while loop to control the menu (main loop) Uses any sort of counting loop to calculate the sum. Uses a switch statement on the first character of the user's input - Uses nested loops to print the box

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions