float answer;
//How do I get answer to be decimal
answer = 10 - 2/5 - 8/5 - 3/8;
cout<<answer;
//endl;
return 0;
float answer;
//How do I get answer to be decimal
answer = 10 - 2/5 - 8/5 - 3/8;
cout<<answer;
//endl;
return 0;
cout<<(int)answer;
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
that dont work me son
Hmmm. I just answered a similar question. But here you go anyway.
cout << (float)answer;
but you may also want to do your operations like this:
Code:float answer; answer = 10 - 2.0/5.0 - 8.0/5.0 - 3.0/8.0;
master, the reason you just answered a similar questioned is because i was going to answer this post, and found that i had no idea either!
but anyway, you shouldn't have to put:
the (float) type casting is not necessary, but if you still cant do it that way just use double insteadCode:cout << (float)answer << endl;
[email protected]
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials
I see that the cycle of life has been completed then Anyway, I'm not too sure way the 2f/5f thing didn't work for you. I'm using mingw though. I don't know why something like that would make a difference. Oh well.