
February 12th, 2004, 04:08 AM
|
Registered User
|
|
Join Date: Feb 2004
Posts: 28
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
I'm gonna assume your main problem is that you are not getting the right answer, so I'm not gonna address issues like whether or not the code should be seperated to be more readable. The basic problem is that if you do ANY operation with an integer, the answer will be an integer. You need to cast the integers to type double (or float, if you must) and use constants of type double (of course, you don't have to permanently change the type of your declared constant if you don't want to). So the formula would look like this:
cout << (price_per_yard*(((static_cast<double>length_ft*static_cast<double>width_ft)/2.0)/3.0))*static_cast<double>STAX;
Now, I have used double because I would declare price_per_yard as a double (just a thang...), I am, however, 99.9% sure you could just change everywhere I have double to float... Just note also that where you divide by 2 and then 3, you need to divide by 2.0 and 3.0.
Hope this helps...
|