Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- int[] billValues = { 1, 5, 10, 20, 50, 100 };
- int[] myBills = new int[6]; // which bills I have
- int[] paidBills = new int[6]; // what bills I paid
- int[] changeBills = new int[6]; // what bills I got as change
- int amountToPay = 150;
- int amountLeftToPay = amountToPay;
- myBills[0] = 0; //1
- myBills[1] = 0; //5
- myBills[2] = 1; //10
- myBills[3] = 0; //20
- myBills[4] = 0; //50
- myBills[5] = 2; //100
- int Total = (myBills[0] * 1) + (myBills[1] * 5) + (myBills[2] * 10) + (myBills[3] * 20) + (myBills[4] * 50) + (myBills[5] * 100);
- if(amountToPay > Total)
- {
- Console.WriteLine("Not enough money");
- Console.ReadLine();
- return;
- }
- for (int i = billValues.Length - 1; i >= 0; i--) // biggest FIRST
- {
- // basically keep paying with e.g. hundreds as long as the amount
- // left is 100+, etc, then go on to 50's etc
- while (amountLeftToPay > 0 && myBills[i] > 0)
- {
- amountLeftToPay -= billValues[i];
- myBills[i]--;
- paidBills[i]++;
- Total -= billValues[i];
- }
- }
- int Change = amountLeftToPay *-1;
- Console.WriteLine("1$: " + myBills[0]);
- Console.WriteLine("5$: " + myBills[1]);
- Console.WriteLine("10$: " + myBills[2]);
- Console.WriteLine("20$: " + myBills[3]);
- Console.WriteLine("50$: " + myBills[4]);
- Console.WriteLine("100$: " + myBills[5]);
- Console.WriteLine("Total$: " +Total);
- Console.WriteLine("Change: "+Change);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement