My assignment is to have a program that creates a structure called Circle that has radius, diameter, area, and circumference. The program also needs 4 functions under the structure. Circle getCircleData(); void calculateCircleData(Circle &); void displayCircleData(Circle); and bool tryAgain();. Right now my code has a "do" statement in between the main and the first function, because it has to be able to run the functions again, with ANOTHER circle, while the bool statement returns true. I know that won't work because the "do" is not inside any function. But I don't know where to put it. I think my program has other problems too, but I'm not sure what they are. Anyways, if you could help me out, it would be greatly appreciated.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
struct Circle
{
double radius;
double diameter;
double area;
double circumference;
Circle( )
{
radius = 0;
diameter = 0;
area = 0;
circumference = 0;
}
};
Circle getCircleData();
void calculateCircleData(Circle &);
void displayCircleData(Circle);
bool tryAgain();
int main()
{
cout << "Welcome to our Circle Calculator" << endl;
cout << "--------------------------------" << endl;
return 0;
}
do
{
Circle getCircleData ( )
{
Circle c1;
cout << "Enter the radius of the circle (number greater than 0)" << endl;
cin >> c1.radius;
return c1;
}
void calculateCircleData (Circle &value)
{
Circle c1;
c1.diameter = (c1.radius * 2);
c1.area = (c1.radius * c1.radius * 3.14159);
c1.circumference = (2 * c1.radius * 3.14159);
}
void displayCircleData (Circle)
{
Circle c1;
cout << "The circle data is:" << endl;
cout << "Radius: " << c1.radius << fixed << setprecision(2) << endl;
cout << "Diameter: " << c1.diameter << fixed << setprecision(2) << endl;
cout << "Area: " << c1.area << fixed << setprecision(2) << endl;
cout << "Circumference" << c1.circumference << fixed << setprecision(2) << endl;
}
}
while (tryAgain());
bool tryAgain ()
{
char again;
cout << "Do you want to try again? (y/n)" << endl;
cin >> again;
if ((again == 'y')||(again == 'Y'))
{
return 1;
}
else
{
return 0;
}
}