subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:00
Which factor is the most important when choosing a website host? whether customers will make secure transactions the number of email accounts provided the purpose of the website the quality of the host control panel
Answers: 3
question
Computers and Technology, 23.06.2019 01:30
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
Another name for addicting games.com
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
Why is an outfitting a workspace with video games in a technology development company considered a strategic use of money
Answers: 1
You know the right answer?
Copy the following code and run it. You should break it into the following 3 functions
getVal...
Questions
question
Mathematics, 02.04.2020 20:14
question
Mathematics, 02.04.2020 20:14