I need help figuring out this problem. I need to ask the user if they want the program to calculate Diameter, Circumference or Area and I also need the the user to input the radius after that. But after that I am having trouble making the program only display the relevant answer. If the user designates Diameter I only want to display the answer for diameter.
Here is the problem as it is on my lab sheet: Write code that calculates and prints the diameter, the circumference, or the area of a circle,
given the radius. The program inputs two data items. The first is a character—‘D’ (for diameter), ‘C’ (for
circumference), or ‘A’ (for area)—to indicate the calculation needed. The next data value is a floatingpoint
number indicating the radius of the particular circle. The program should print the input data. The
output should be labeled appropriately. For example, if the input is: A 6.75 your program should print
something like this:
The area of a circle with radius 6.75 is 143.14.
Here is what I have so far:
using namespace std;
char D, C, A;
cout << "What do you want to solve for? (D, C, A)" << endl; cin >> letter; cout << "What is the radius?" << endl; cin >> R; Pi = 3.14159265; Dia = 2 * R; Cir = 2 * Pi * R; Area = Pi * pow(R,2); if (letter == D) //error C4700 uninitialized local vairbale 'D' used cout << "The Diameter of the Circle is: " << Dia << endl; if (letter == C) //error C4700 uninitialized local vairbale 'C' used cout << "The Circumference of the Circle is: " << Cir << endl; if (letter == A) //error C4700 uninitialized local vairbale 'A' used cout << "The Area of the Circle is: " << Area << endl; return 0;
It looks like you're new here. If you want to get involved, click one of these buttons!