|
-
July 14th, 2011, 10:00 PM
#22
Re: Loop Problem
 Originally Posted by Lindley
You should separate the input and output format from the internal storage format. Even if you're counting cents internally (so that $157.03 becomes 15703 cents), that doesn't mean that you shouldn't be able to accept "157.03" as an input in dollars. You validate the input, then you convert it to your internal format. Similarly, you can convert your count of cents back to the conventional notation on ouput:
Code:
void outputmoney(ostream &out, int totalcents)
{
int dollars = totalcents/100;
int cents = totalcents%100;
out << "$" << dollars << "." << cents;
}
outputmoney(cout, 15703); // test call
Thanks! that is a great explanation. I will try and figure it out and change my code. That should fix the problem. The double is causing the problem here. Thank you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|