Advertisement
Guest User

Untitled

a guest
May 1st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication11
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double[] coins = { 10, 5, 2, 1, 0.5, 0.1 };
  14.             int[] numOfCouns = { 0, 0, 0, 0, 0, 0 };
  15.             double price, pay, change;
  16.             Console.Write("Enter the price of the item: ");
  17.             price = double.Parse(Console.ReadLine());
  18.             Console.Write("Enter your payment: ");
  19.             pay = double.Parse(Console.ReadLine());
  20.  
  21.             change = pay - price;
  22.  
  23.             Console.WriteLine("You need to pay: ");
  24.        
  25.             for (int i = 0; i < coins.Length; i++)
  26.             {
  27.                 while (coins[i] <= change)
  28.                 {
  29.                     numOfCouns[i]++;
  30.                     change -= coins[i];
  31.                 }
  32.                 Console.WriteLine("{0} coins of {1}", numOfCouns[i], coins[i]);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement