|
-
September 14th, 2010, 01:56 PM
#1
Im losing a .01 somewhere
Hi this program is for homework and it converts dollars and change into there respective values
but if i enter .02 i get .01 I can not see where its getting lost.
#include <iostream.h>
#include <stdlib.h>
int main()
{
float m;
int a , d , rd , h , rh , q , rq , di , rdi , n , p;
cout << "enter amount to change" << endl;
cin >> m;
a = static_cast<int> (m*100);
d = a/100;
rd = a%100;
h = rd/50;
rh = rd%50;
q = rh/25;
rq = rh%25;
di = rq/10;
rdi = rq%10;
n = rdi/5;
p = rdi%5;
cout << "Dollars " << d << "\nHalf dollars " << h << "\nQuarters " << q <<
"\nDimes " << di << "\nNickles " << n << "\nPennies " << p << endl;
system("pause");
return 0;
}
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
|