Computers and Technology

Copy the following code and run it. You should break it into the following 3 functions
getValidInput - which asks the user to enter the radius and then make sure that it is valid before returning it
circleCalculations - which uses the raius passed in to calculate both the area and the circumference. The area is returned
printResults - sets the fixed and precision and prints out the output

#include
#include
using namespace std;

const double PI = 3.14159;
int main()
{
int radius;
double area;
double circ;

cout << "Type a -1 for radius to exit" << endl;
cout << "Enter the radius: ";
cin >> radius;
while (radius >= 0)
{
circ = 2 * PI * radius;
area = PI * pow(radius, 2);

cout. setf(ios::fixed);
cout. precision(1);
cout << "A circle with radius " << radius << " has a circumference of "
<< circ << " and an area of " << area << endl << endl;

cout << "Enter the radius: ";
cin >> radius;
}
}
Sample Output

Type a -1 for radius to exit
Enter the radius: 5
A circle with radius 5 has a circumference of 31.4 and an area of 78.5

Enter the radius: -4
Radius cannot be negative - try again!!!
Enter the radius: -7
Radius cannot be negative - try again!!!
Enter the radius: 12
A circle with radius 12 has a circumference of 75.4 and an area of 452.4

Enter the radius: 7
A circle with radius 7 has a circumference of 44.0 and an area of 153.9

Enter the radius: -1

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 02:00, sabrinarasull1pe6s61
Which of the following is a way the operating system prevents unknown or unauthorized users from accessing the system?
Answers: 2
image
Computers and Technology, 23.06.2019 08:30, Bradgarner772
Based on your knowledge of a good network, describe what you think is a perfect network would be. what kind of information and resources could users share on this network. what would the network administrator do? what kind of communication would be used?
Answers: 1
image
Computers and Technology, 23.06.2019 16:30, 19thomasar
How to do this programming flowchart?
Answers: 3
image
Computers and Technology, 24.06.2019 08:20, bob4059
Evaluate the scenario below and indicate how to handle the matter appropriately. situation: michael received an e-mail from what he thought was his doctor’s office, requesting his social security number. since he had just been in to see his doctor last week, he replied to the e-mail with his social security number.
Answers: 2
Do you know the correct answer?
Copy the following code and run it. You should break it into the following 3 functions
getVal...

Questions in other subjects:

Konu
Chemistry, 28.01.2021 18:40
Konu
Mathematics, 28.01.2021 18:40