Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 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 Coins_2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             decimal price = decimal.Parse(Console.ReadLine());
  14.             decimal paid = decimal.Parse(Console.ReadLine());
  15.             decimal amountChange = paid - price;
  16.  
  17.             int onelev = 0;
  18.             int fifty = 0;
  19.             int twenty = 0;
  20.             int ten = 0;
  21.             int five = 0;
  22.             int two = 0;
  23.             int one = 0;
  24.  
  25.             while (amountChange != 0)
  26.             {
  27.  
  28.                 if (amountChange >= 1m)
  29.                 {
  30.                     amountChange -= 1m;
  31.                     onelev++;
  32.                 }
  33.                 else if (amountChange >= 0.5m)
  34.                 {
  35.                     amountChange -= 0.5m;
  36.                     fifty++;
  37.                 }
  38.                 else if (amountChange >= 0.2m)
  39.                 {
  40.                     amountChange -= 0.2m;
  41.                     twenty++;
  42.                 }
  43.                 else if (amountChange >= 0.1m)
  44.                 {
  45.                     amountChange -= 0.1m;
  46.                     ten++;
  47.                 }
  48.                 else if (amountChange >= 0.05m)
  49.                 {
  50.                     amountChange -= 0.05m;
  51.                     five++;
  52.                 }
  53.                 else if (amountChange >= 0.02m)
  54.                 {
  55.                     amountChange -= 0.02m;
  56.                     two++;
  57.                 }
  58.                 else if (amountChange >= 0.01m)
  59.                 {
  60.                     amountChange -= 0.01m;
  61.                     one++;
  62.                 }
  63.             }
  64.  
  65.             if (onelev > 0) Console.WriteLine($"{onelev} x 1 lev");
  66.             if (fifty > 0) Console.WriteLine($"{fifty} x 50 stotinki");
  67.             if (twenty > 0) Console.WriteLine($"{twenty} x 20 stotinki");
  68.             if (ten > 0) Console.WriteLine($"{ten} x 10 stotinki");
  69.             if (five > 0) Console.WriteLine($"{five} x 5 stotinki");
  70.             if (two > 0) Console.WriteLine($"{two} x 2 stotinki");
  71.             if (one > 0) Console.WriteLine($"{one} x 1 stotinka");
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement