PDA

Click to See Complete Forum and Search --> : Code check please


Aerials
Apr 25th, 2002, 06:13 PM
I'm trying to make a prog that finds the area of a circle.
After asking the user the radius of the circle it should display the area after a calculation.
But the program wont display the final result. Why?

#include <iostream.h>
#include <conio.h>

int main()
{
int radius;
const double pi=3.14;
cout<<"Find the area of a circle!\n";
cout<<"Enter the radius of the circle you want to find the radius of(Works best with whole numbers): ";
cin>>radius;
cout<<"The area is: "<<(radius*pi);
getch();
return 0;
}

I'd appreciate if I could get help ASAP

Technocrat
Apr 25th, 2002, 06:31 PM
#include <iostream.h>
#include <conio.h>

int main()
{
int radius;
const double pi=3.14;
cout << "Find the area of a circle!" << endl;
cout << "Enter the radius of the circle you want to find the radius of(Works best with whole numbers): ";
cin>>radius;
cout << "The area is: "<< (radius*pi) << endl;
getch();
return 0;
}

Aerials
Apr 25th, 2002, 06:38 PM
thx :D

Technocrat
Apr 25th, 2002, 06:48 PM
Sure :)
Just remember to tell the iostream that you are done with a line from now on and you should be ok. ;)

Aerials
Apr 25th, 2002, 08:53 PM
:p

CornedBee
Apr 26th, 2002, 09:47 AM
endl does not only start a new line but also flushes the ouput buffer, so things are actually written to the screen.

[Digital-X-Treme]
Apr 26th, 2002, 11:24 AM
cout<<"The area is: "<<(radius*pi);

The area of a circle is pi * r^2. ;)

Aerials
Apr 26th, 2002, 03:13 PM
oops :rolleyes:

CornedBee
Apr 27th, 2002, 05:46 AM
but in this case, you shouldn't do pi^2 but rather pi*pi (it's faster)

Lord_Rat
Apr 28th, 2002, 11:21 PM
That would be pi*r*r right?

[praetorian]
Apr 29th, 2002, 02:11 AM
yepp, correct