# calculating dimensions of a cirlce

• 09-27-2004
milamysl
calculating dimensions of a cirlce
Hi,
My menu driven program that repeatedly calculates and prints the diameter of, circumference or area of circle, given the radius,
is not doing what I want it to do...
Can code doc / code friend point out how to make it work?
Thanks
Code:

```#include<iostream> using std::cout; using std::cin; using std::endl; #include <iomanip> using std::setprecision; int main() {         double Diameter, Area, Circumference, radius;         char D=0, A=0, C=0, X=0, input=0;         cout << "Please pick an option: " << endl                   << "Calculate the diameter of the circle:  'D' " << endl                 << "Calculate the area of the circle:      'A' " << endl                 << "Calculate the circumference:                'C' " << endl                 << "Exit the program:                                        'X' " << endl;                         cin >> ( D || A || C || X )         cout << setprecision ( 2 )                 {         if ( input == D ){                         cout << "Enter the lenght of the radius: " << endl;                         cin >> radius;                         Diameter = 2* radius ;                 cout << " The diameter of circle with radius " << radius << "is " << Diameter << endl;         }                        if ( input == A )                 {                cout << "Enter the lenght of the radius: " << endl;                         cin >> radius;                         Area = 3.14 * radius * radius ;                 cout << " The area of cirlce with radius " << radius << "is" << Area << endl;                 }                 if ( input == C)                 {        cout << "Enter the lenght of radius: " << endl;                         cin >> radius;                         Circumference = 2 * 3.14 * radius ;                         cout << "The circumference of the circle with radius " << radius << "is " << Circumference << endl;                 }                 if ( input == X)                         cout << "Good bye" << endl;         }                 return 0; }```
• 09-27-2004
PorkyChop
Please use code tags next time.

It looks like your main problem is this:
Code:

`cin >> ( D || A || C || X );`
That line should be:
Code:

`cin >>input;`
Also, you may want to look into switch statements. For example:
Code:

```switch( input ) //Make some decisions based on input {         case 'D': //Synonymous with "If input is == 'D' "                 //Diameter calculations         break;                 case 'A':                 //Area calculations         break;                 case 'C':                 //Circumference         break;                 case 'X':                 //Leave         break;                 default:                 //Unexpected input, problem }```
Note how I put character literals in single quotes ( eg 'D', not D ). There are some other logical problems with that code but I think that's enough for you to absorb.
• 09-27-2004
master5001
I'm not sure if you cut and paste incorrectly or what, but you also have a nasty habbit of not putting semicolons at the end of a line of code. Also don't forget your code tags.