ok radius

This is a discussion on ok radius within the C++ Programming forums, part of the General Programming Boards category; Ok i'm doing a function for the radius of a circle.. power area (float area = PI * radius correct ...

  1. #1
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    Question ok radius

    Ok i'm doing a function for the radius of a circle..
    power area (float
    area = PI * radius
    correct me if i'm wrong..

    float area = 0;
    float PI = 3.1415;
    float radius = 0;

    cout >> "Enter the radius:" >> endl;
    cin >> radius;

    cout >> " The area of the circle is :" >> area >> endl;
    The one & only!!

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    asking well articulated questions will get you a better responses around here. the above failing, at least _ask_ a question

  3. #3
    Unregistered
    Guest
    ok my question is do i have the formula right or not. ;0

  4. #4
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    radius part II

    ok the if statment is not working & I think i have the radius formula wrong..

    #include <iostream>
    #include <cctype>
    #include <iomanip>
    #include <string>
    using namespace std;

    //float power(float x, int y)

    int main()

    {
    int choice = 0;
    int start = 0;
    int ending = 0;
    int hours = 0;
    int min = 0;
    int sec = 0;

    float area = 0;
    double PI = 3.1415;
    float radius = 0;




    cout << "ITSE 2431" << endl;

    cout << "Spring 2002 " << endl;

    cout << "1. Calculate Average Velocity " << endl;
    cout << "2. Calculate Area of a Circle " << endl;
    cout << "3. Quit " << endl;

    cout << "Make a selection (1-3): " << endl;


    cin >> choice;

    switch (choice)

    do
    {
    case 1:
    cout << "Calculate Average Velocity" << endl;
    cout << "Starting Mile Marker: " << endl;
    cin >> start;
    cout << "Ending Mile Marker: " << endl;
    cin >> ending;
    cout << "Elapsed Time: " << endl;
    cout << " Hours: " << endl;
    cin >> hours;
    cout << " Minutes: " << endl;
    cin >> min;
    cout << "Seconds: " << endl;
    cin >> sec;

    break;

    case 2:


    cout << "Calculate Area of a Cirlce" << endl;

    cout << "The area of a circle with radius " << "is " << "units." << endl;

    area = PI * radius;


    cout << "Enter the radius:"<< endl;
    cin >> radius;

    cout << " The area of the circle is :" << area << endl;

    break;

    default:
    cout << "You entered a wrong number" << endl;

    }while

    if(choice = 3);
    cout << "Quit" << endl;
    system ("CLS");

    cout << setw(50)<< "Program terminated by user "
    << endl;
    break;


    return 0;

    }
    The one & only!!

  5. #5
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    you're talking to the one and only blight2c, and all you want to know is how to figure the area of a circle. if i recall it's
    a=pi r^2

  6. #6
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    sorry to give you a hard time buddy. i changed you switch(choice) around --you don't need the dowhile() in there. try emulating it and tell me what happens.

    Code:
    switch (choice) 
    {
    	case 1: 
    		cout << "Calculate Average Velocity" << endl; 
    		cout << "Starting Mile Marker: " << endl; 
    		cin >> start; 
    		cout << "Ending Mile Marker: " << endl; 
    		cin >> ending; 
    		cout << "Elapsed Time: " << endl; 
    		cout << " Hours: " << endl; 
    		cin >> hours; 
    		cout << " Minutes: " << endl; 
    		cin >> min; 
    		cout << "Seconds: " << endl; 
    		cin >> sec; 
    
    		break; 
    
    	case 2: 
    
    		cout << "Calculate Area of a Cirlce" << endl; 
    		cout << "The area of a circle with radius " 
    			 << "is " << "units." << endl; 
    }

    how old are you, if you don't mind me asking?
    Last edited by blight2c; 05-01-2002 at 10:11 PM.

  7. #7
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    private

    if u want to know that info
    please make it "PRIvATE"
    The one & only!!

  8. #8
    Unregistered
    Guest
    if (choice = 3);
    cout << "Quit" << endl;
    system ("CLS");
    should be

    Code:
    if (choice == 3); 
    cout << "Quit" << endl; 
    system ("CLS");

  9. #9
    Registered User abbynormal87's Avatar
    Join Date
    Apr 2002
    Posts
    17

    thanks

    thanks unregistered ... but now i have the problem where i was case 1 & 2 to keep going unless I press the option of 3.

    Like a never ending loop till i press the option 3 to quit the program
    The one & only!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is wrong with my code?
    By dakarn in forum C Programming
    Replies: 6
    Last Post: 10-14-2008, 05:16 AM
  2. Sine (Sin) Algorithm Help
    By StaticKyle in forum C Programming
    Replies: 52
    Last Post: 05-13-2008, 08:37 AM
  3. Relating classes using composition
    By clegs in forum C++ Programming
    Replies: 12
    Last Post: 11-05-2007, 11:56 PM
  4. Backdooring Instantaneous Radius of Curvature & Functions
    By just2peachy in forum C++ Programming
    Replies: 8
    Last Post: 10-06-2004, 12:25 PM
  5. help with writing function that multiplys the radius
    By Earl Lee in forum C Programming
    Replies: 6
    Last Post: 10-03-2002, 04:33 PM

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