Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Chapter 4 : Programming Project 2 Unlimited tries Write a program that displays the following menu. The symbols show where newline characters (

Chapter 4: Programming Project 2
Unlimited tries
Write a program that displays the following menu. The
symbols show where newline characters ("
") should be displayed:
Geometry Calculator
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit
Enter your choice (1-4):
If the user enters 1: The program should print the following string as a prompt:
"
Enter the circle's radius: "
The program should then read the radius of the circle as input and then calculate the circle's area using the following formula:
Area =\pi r2
In your calculation, use 3.14159 for \pi and the radius of the circle for r.
The program should then print the string "
The area is ", followed by the area, followed by a newline.
If the user enters 2: The program should print the following string as a prompt:
"
Enter the rectangle's length: "
The program should read the length as input and then print the following string as a prompt:
"Enter the rectangle's width: "
The program should read the width as input and then calculate the rectangle's area using the following formula:
Area = length \times width
The program should then print the string "
The area is ", followed by the area, followed by a newline.
If the user enters 3: The program should print the following string as a prompt:
"Enter the length of the base: "
The program should read the base as input and then print the following string as a prompt:
"Enter the triangle's height: "
The program should read the height as input and then calculate the triangle's area using the following formula:
Area = base \times height \times 0.5
The program should then print the string "
The area is ", followed by the area, followed by a newline.
If the user enters 4: The program should print the string "Program ending.
", and then end.
Input Validation:
The only valid menu choices the user can make are 1,2,3, or 4. If the user makes a menu choice other than one of these numbers, the program should print the following strings and then end:
"The valid choices are 1 through 4. Run the
"
"program again and select one of those.
"
If the user enters a negative number for the circle's radius, print the following string, and then end:
"
The radius can not be less than zero.
"
If the user enters a negative number for the rectangle's length OR width, print the following string, and then end:
"
Only enter positive values for length and width.
"
If the user enters a negative number for the triangle's base OR height, print the following string, and then end:
"
Only enter positive values for base and height.
"
Sample Run
Geometry Calculator
1. Calculate the area of a Circle
2. Calculate the area of a Rectangle
3. Calculate the area of a Triangle
4. Quit
Enter your choice (1-4): 1
Enter the circle's radius: 1
The area is 3.14159
Sample Run
Geometry Calculator
1. Calculate the area of a Circle
2. Calculate the area of a Rectangle
3. Calculate the area of a Triangle
4. Quit
Enter your choice (1-4): 2
Enter the rectangle's length: 10
Enter the rectangle's width: 20
The area is 200

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions