February 11th, 2003, 03:29 AM
|
#2 (permalink)
|
| Ultimate Member
Join Date: Jun 2002 Location: Iowa
Posts: 2,879
|
Figured it out Code: #include <iostream>
using namespace std;
/* This is to Figure the Area of a Circle,
Added a loop to this to allow for continued use
until the program encounters another number besides 1 */
float areaofcircle (float x, float y)
{return ((x*x)*y);}
int main()
{
int looping;
do{
cout << "\n";
cout << "\n";
cout << "******************************************** \n";
cout << "******************************************** \n";
cout << "\n";
cout << "\n";
cout << " AREA OF A CIRCLE \n";
cout << "\n";
cout << "\n";
cout << "To figure the area of a circle we need to \n";
cout << "have the radius and pi. \n";
cout << "The formula for the area of a circle is :\n";
cout << " PI X Radius(2) = AREA \n";
float a, b, c ;
cout << "\n";
cout << "Please enter the Radius of the circle: ";
cin >> a;
cout << "PI=3.1415 (for our purposes here): ";
b=3.1415 ;
cout << "\n";
cout << "\n";
c=areaofcircle(a,b);
cout << "The AREA of the circle with a radius of " << a << " is " << c << " \n";
cout << "\n";
cout << "\n";
cout << "Would you like to do this again?? \n";
cout << "Type 1 to continue, or any other key to exit.. \n";
cin >> looping;
if ( looping != 1 )
looping = 2;
}while ( looping == 1 );
cout << "\n";
cout << "Thanks for using my Area of a Circle program !! \n";
cout << "Good Bye !!\n";
cout << "******************************************** \n";
cout << "******************************************** \n";
cout << "\n";
cout << "\n";
return 0;
}
I just added the line : Code: if ( looping != 1 )
looping = 2; Now it exits gracefully if a letter or other key is hit instead of the 1 key. |
| |