Jump to content
  • Advertisement

Archived

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

cannotcompute

What's wrong with my code? please look.

This topic is 6151 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!