How to make Give Change program in c#
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace bills { class Program { static void Main(string[] args) { Console.Write("Price?"); int prince = Convert.ToInt32(Console.ReadLine()); Console.Write("Paid?"); int paid = Convert.ToInt32(Console.ReadLine()); int remainder = paid - prince; Console.Write("Your change is " + remainder+":"); int i,a,b,c,d,f,g,h; //If the remainder is greater then and equal to 100 then this block is executed. while(remainder>=100) { // we are using the a variable for counting the number of 100 note. a = remainder/100; remainder = remainder%100; // we are using FOR loop for printing the "100" a times. a is the variable. for (i = 1; i <= a;i++ ) Console.Write("100"+" "); } while (remainder >= 50) { b = remainder / 50; remainder = remainder % 50; for (i = 1; i <= b; i++) Console.Write("50" + " "); } while (remainder >= 20) { c = remainder / 20; remainder = remainder % 20; for (i = 1; i <= c; i++) Console.Write("20" + " "); } while (remainder >= 10) { d = remainder / 10; remainder = remainder % 10; for (i = 1; i <= d; i++) Console.Write("10"+" "); } while (remainder >= 5) { f = remainder / 5; remainder = remainder % 5; for (i = 1; i <= f; i++) Console.Write("5"+" "); } while (remainder >= 2) { g = remainder / 2; remainder = remainder % 2; for (i = 1; i <= g; i++) Console.Write("2"+" "); } while (remainder >= 1) { h = remainder / 1; remainder = remainder % 1; for (i = 1; i <= h; i++) Console.Write("1"+" "); } Console.ReadLine(); } } }
No comments:
Post a Comment