Alrite, how do break money down using c++
eg:the user enters a value, and then the program breaks it up
for this example $20.20 to be broken down to how many, 1 dollars, .50 cents, 20 cents, .10 cents and .05 cents...
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int Mod, Modu, value, deposit, change;
Your problem is that Modu/50 gets evaluated as 0. The safe way of doing it is to not use modulo. Then the algorithm becomes something like:
1 2 3 4 5 6 7 8 9 10 11 12
int deposit=2020 // as per your example
int coins=deposit/100 // evaluating to 20
cout << coins << " 1 dollar" << endl;
change=deposit-(100*coins); // this is now 20.
int coins=change/50 // evaluating to 0
cout << coins << " 50c coins" << endl;
change=deposit-(50*coins); // this is still 20.
int coins=deposit/20 // evaluating to 1
cout << coins << " 20c coins" << endl;
change=deposit-(20*coins); // this is now 0.
If you want to use modulo, then change "Modu = Modu / 50;" to "change= Modu/50; Modu = Modu%50" and repeat for the rest