Hi~~~
I'm new to the forums (and C++), and hope someone can help me with a very basic program. I apologize if any etiquette has been violated.
The following is a very basic money sorting programs that works*, in which a given amount is broken up to its maximum amount of dollars, quarters, etc. (I left out nickels and pennies to shorten this post).
Code:/*Money Sorter*/ #include "iostream" #include "cmath" using namespace std; int main() { double amount; cout<<"enter your amount in wallet"<<endl; cin>>amount; int dollars, quarters, dimes, nickels, pennies; dollars=int(amount); //represents amount in full dollars quarters=(int)((amount-dollars)/.25); //leftover quarters cout<<dollars<<" "<<quarters<<endl; dimes=(int)((amount-dollars-quarters*.25) /.1 ); //dimes left cout<<dimes<<endl; system("pause"); return 0; }
*So I believe this program is good with one exception. When I typed in $15.20, it gives you 15 dollars, 0 quarters, and 1 dime. I'm not sure why or how I can fix it to be 2. My best guess is that quarter is ultimately a double, which messes up the intent of the italicized portion.
To be honest, I'd rather just move on and learn other things, but I thought this was weird enough for me to sign on to the forums and ask for an opinion.
Cheers!



1Likes
LinkBack URL
About LinkBacks




