calculating dimensions of a cirlce

This is a discussion on calculating dimensions of a cirlce within the C++ Programming forums, part of the General Programming Boards category; Hi, My menu driven program that repeatedly calculates and prints the diameter of, circumference or area of circle, given the ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    1

    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;
    
    }
    Last edited by Salem; 09-27-2004 at 03:24 PM. Reason: Maybe I should just delete posts without code tags

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    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.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 45
    Last Post: 04-02-2008, 09:10 AM
  2. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM
  5. Calculating window sizes
    By Mox in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2001, 08:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21