/*Make a program that allows the user to input either the radius, diameter, or area of the circle.
The program should then calculate the other 2 based on the input. (Beginner)*/
#include <iostream>
using namespace std;
#include <cmath>
int main ()
{
double pi = 3.14159265, radius, diameter, area;
char choice;
bool quit = false;
do
{
cout << "Enter D for diameter, R for radius, or A for area: ";
cin >> choice;
if (choice == 'D' || choice == 'd')
{
cout << "Enter the value for the diameter of your circle: ";
cin >> diameter;
cout << endl;
radius = diameter/2;
area = pi * radius;
cout << "Diameter: " << diameter << endl
<< "Radius: " << radius << endl
<< "Area: " << area << endl;
cout << "Would you like to continue? (Y/N): ";
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << endl;
continue;
}
else
quit = true;
}
else if (choice == 'R' || choice == 'r')
{
cout << "Enter the value for the radius of your circle: ";
cin >> radius;
cout << endl;
area = pi * radius;
diameter = radius * 2;
cout << "Diameter: " << diameter << endl
<< "Radius: " << radius << endl
<< "Area: " << area << endl;
cout << "Would you like to continue? (Y/N): ";
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << endl;
continue;
}
else
quit = true;
}
else if (choice == 'A' || choice == 'a')
{
cout << "Enter the area of your circle: ";
cin >> area;
cout << endl;
diameter = sqrt((4*area)/pi);
radius = diameter/2;
cout << "Diameter: " << diameter << endl
<< "Radius: " << radius << endl
<< "Area: " << area << endl;
cout << "Would you like to continue? (Y/N): ";
cin >> choice;
if (choice == 'Y' || choice == 'y')
{
cout << endl;
continue;
}
else
quit = true;
}
}while (quit == false);
cout << endl;
cin.get();
return 0;
}
This is my completed program to one of the practice programs given in the sticky at the top of the forums. In the book I am learning from it states that using the "continue" and "break" keywords shoudl be avoided when possible. Is there a way to have this run without using "continue"? Also, do any of you have any suggestions as to making this program any better? (i.e. additions, or better way to code). Thanks again for all of you guys help. :)
Also, sorry about the coloring of the text. It does it automatically when I copy and paste between code tags. I also found out that in order for my text to stay indented I have to use firefox instead of ie7.