problem with C++ program

This is a discussion on problem with C++ program within the C++ Programming forums, part of the General Programming Boards category; this is part of my program...I'm trying to figure out how to test the value of the radius so that ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Talking problem with C++ program

    this is part of my program...I'm trying to figure out how to test the value of the radius so that it is not equal to zero..if it is...an error message must print and end the program????

    void area_circumofcircle()
    {
    float r1;
    float r2;
    float Area;
    float Circum;
    const double pi=3.14159;




    cout << endl << endl << "Calculate The Area and Circumference Of A Circle!\n\nEnter A Floating Point For The Radius ";
    cout << endl << "Enter radius 1: ";
    cin >> r1;
    cout << endl << "Enter radius 2: ";
    cin >> r2;
    Area = pi * r1 * r2;
    cout << endl << endl << "The area of circle is : "<< Area;
    Circum = 2 * pi * r1;
    cout << endl << endl << "The circumference of circle is : "<<Circum;

    }

  2. #2
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Code:
    if(!r1 || !r2)
    {
    cout<<"You put in a zero radius dummy";
    exit(0);
    }
    though you won't see the message cos it will end dead quick.

    Another thing, don't you want the radius to equal pi * r1 * r1?

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    2

    Talking C++ problem

    Thanks..but I figured it out a different way...grin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 10:10 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 01:34 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM
  4. Replies: 20
    Last Post: 06-12-2005, 11:53 PM

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