Search:
Forum
Beginners
easy question
easy question
Apr 8, 2009 at 11:15pm UTC
shakethatmoney
(13)
I want to do this calculation:
float interest;
float initBalance;
interest = (1/12) * (3/100) * initBalance;
cout << interest;
Problem is, (1/12) and (3/100) end up getting rounded to 0. What data type should I be using to prevent this?
Thanks.
Apr 8, 2009 at 11:19pm UTC
Disch
(13742)
(1.0f/12.0f) * (3.0f/100.0f)
The reason is that without a decimal point, C++ defaults to type 'int' and not to type 'float'. Putting the 'f' at the end indicates the numbers are to be treated as floats (without the 'f' but with the decimal point, they're treated as 'double's).
Apr 8, 2009 at 11:32pm UTC
shakethatmoney
(13)
haha awesome thank you very much.
Topic archived. No new replies allowed.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs