what is wrong in this c++ programe

I tried the following code
using namespace std;
int main()
// calculate are of a circle
float radius,area;
cout<< area;
return 0;
this gives a list of errors like undefined reference to std::cin etc…
what is wrong with programe?

How did you compile it? Did you use C compiler instead of C++ compiler?

Also, have a look at this:


Header file? With out .h?


g++ radius.cpp -o radius

Also, use the value of pi lol!

Yeah, at least 8 decimals. :slight_smile:
ps.: no google!

Unless you are in Iowa, where you can use the value 3. lol! (Actually to be fair to Iowa, that proposal never got past the committee.)

Trivia: When I was a student, I found 355/113 a much better approximation than the 22/7 some people quote. It’s accurate to 1 in 10^7.

I used the command gcc

with gcc area.cpp -o a.out

Well that explains it, if you want to compile a C++ program you should do:

g++ -o area area.cpp

No need to do -o a.out that’s the default anyway.

thank you very much for the help it works!

I’m not sure what compiler you are using, but I have found something useful related to PI. I’m using GCC 4.3.3. Instead of creating your own constant, check to see if you have M_PI available to you within the math package.

I’d also recommend using some sort of IDE for starters. I am using Netbeans 6.5 with the C/C++ plugin and it allows me to debug C and C++ programs. You just have to configure your settings in the IDE to point to the appropriate C/C++ compilers.

I am just learning c++, Actually the book i learn is abuot TC, when i tried netbeans it gave out a lot of other files also like make ,main …etc I am not that expert now . I use gedit and g++ command now. All my classmates use windows and TC. I proud to be an odd man out there!!! That too with a free OS software

If you have to use Windows at school and want a free IDE check out devcpp. It works very well and is also open-source.

You can always use the c++ command. Easier to remember in which language you program :wink: