Question: Write code in c++ that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two

Write code in c++ that calculates and prints the diameter, the circumference, or the area of a circle, given the radius. The program inputs two data items. The first is a characterD (for diameter), C (for circumference), or A (for area)to indicate the calculation needed. The next data value is a floating-point number indicating the radius of the particular circle. The program should print the input data. The output should be labeled appropriately. For example, if the input is: A 6.75 your program should print something like this: The area of a circle with radius 6.75 is 143.14. Here are the formulas you need: Diameter = 2r, Circumference = 2r, Area of a circle = r2 where r is the radius. Use 3.14159265 for . Modify your program to perform input validation by making sure that the first character is A or C or D and the value of the radius is greater than zero. An appropriate error message should be printed if invalid data was entered.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!