Archived

This topic is now archived and is closed to further replies.

cannotcompute

What's wrong with my code? please look.

Recommended Posts

#include int main() { float PI = 3.14; float radius; cout << "Please enter the radius: "; cin << radius; cout << "The circumference is " << 2*PI*radius << "." << endl; cout << "The area is " << PI*radius^2 << "."; return 0; } I get 2 errors and 1 warning in vc++6: C:\Program Files\Microsoft Visual Studio\MyProjects\circle\circle.cpp(5) : warning C4305: ''initializing'' : truncation from ''const double'' to ''float'' C:\Program Files\Microsoft Visual Studio\MyProjects\circle\circle.cpp(8) : error C2676: binary ''<<'' : ''class istream_withassign'' does not define this operator or a conversion to a type acceptable to the predefined operator C:\Program Files\Microsoft Visual Studio\MyProjects\circle\circle.cpp(10) : error C2297: ''<<'' : illegal, right operand has type ''char [2]'' Error executing cl.exe. circle.exe - 2 error(s), 1 warning(s) what''s wrong? I looked over it over and over!!

Share this post


Link to post
Share on other sites
Chage to:
float PI = 3.14f;
and
cin >> radius;
and
cout << "The area is " << PI * radius * radius << ".";

~~~~~~~~~~
Martee

Share this post


Link to post
Share on other sites
to give you some advice, try a few things out before asking. any book on c++ would have given you the answer, or if you have MSDN handy, that''s always a good reference to look things up in. not that all of us mind these simple questions, but sometimes we also like to teach some common sense. =)

a2k

Share this post


Link to post
Share on other sites
Be careful with the ^ operator... it''s not what it looks like. It''s actually the bitwise exclusive or operator.

0 ^ 0 == 0
1 ^ 0 == 1
0 ^ 1 == 1
1 ^ 1 == 0

For powers, #include <math.h> and use the pow function.

Share this post


Link to post
Share on other sites