Write a complete C++ console mode program (#includes, etc., but no prologue) to
ID: 3657886 • Letter: W
Question
Write a complete C++ console mode program (#includes, etc., but no prologue) to ask the user to enter the radius (any positive real number) of a circle. Your program should display the area of a circle with that radius, and the volume of a sphere with that radius. (area = PI * radius2 and volume = PI * 4/3 * radius3 ). The result should be displayed with accuracy to 3 decimal digits (ie. 1.234). Make sure you include all the header files needed to support the operations you use. a. Use appropriate data types. b. Make the value of PI (3.14159) a constant in your program. c. Valid input is any positive real number and zero. If the user input is negative, your program should print an error message and not try to compute any results. d. Be sure to display explanatory text to make the input and output clear to the userExplanation / Answer
#include <iostream>
using namespace std;
int main ()
{
// b. Make the value of PI (3.14159) a constant in your program.
const double PI = 3.14159;
double radius;
cout << "Enter the radius: ";
cin >> radius;
// c. Valid input is any positive real number and zero. If the user input is negative, your program should print an error message and not try to compute any results.
if(radius <= 0)
{
cout << "Error: Radius is not positive." << endl;
}
else
{
double area = PI*radius*radius;
// d. Be sure to display explanatory text to make the input and output clear to the user
// The result should be displayed with accuracy to 3 decimal digits
printf("%.3f ", area);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.