Guest User

Untitled

a guest
Nov 10th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.07 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3.  
  4. namespace Uri_Online_Judge
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             double valorMonetario = -1, totalMoedas;
  11.             int notas100=0, notas50=0, notas20=0, notas10=0, notas5=0, notas2=0;
  12.             int moedas1 = 0, moedas50 = 0, moedas25 = 0, moedas10 = 0, moedas5 = 0, moedas01 = 0;
  13.             string[] split;
  14.  
  15.             while(valorMonetario < 0 || valorMonetario > 1000000)
  16.             {
  17.                 valorMonetario = Convert.ToDouble(Console.ReadLine(), CultureInfo.InvariantCulture);
  18.             }
  19.  
  20.             // Parte que conta as notas
  21.             if (valorMonetario.ToString().Contains(","))
  22.             {
  23.                 split = valorMonetario.ToString().Split(',');
  24.                 totalMoedas = Convert.ToDouble(split[1]);
  25.             }
  26.             else
  27.             {
  28.                 totalMoedas = 0;
  29.             }
  30.  
  31.             valorMonetario = valorMonetario - (totalMoedas / 100);
  32.            
  33.  
  34.             if (valorMonetario >= 100)
  35.             {
  36.                 notas100 = Convert.ToInt32(valorMonetario) / 100;
  37.                 valorMonetario -= notas100 * 100;
  38.             }
  39.  
  40.             if (valorMonetario >= 50)
  41.             {
  42.                 notas50 = Convert.ToInt32(valorMonetario) / 50;
  43.                 valorMonetario -= notas50 * 50;
  44.             }
  45.  
  46.             if (valorMonetario >= 20)
  47.             {
  48.                 notas20 = Convert.ToInt32(valorMonetario) / 20;
  49.                 valorMonetario -= notas20 * 20;
  50.             }
  51.  
  52.             if (valorMonetario >= 10)
  53.             {
  54.                 notas10 = Convert.ToInt32(valorMonetario) / 10;
  55.                 valorMonetario -= notas10 * 10;
  56.             }
  57.  
  58.             if (valorMonetario >= 5)
  59.             {
  60.                 notas5 = Convert.ToInt32(valorMonetario) / 5;
  61.                 valorMonetario -= notas5 * 5;
  62.             }
  63.  
  64.             if (valorMonetario >= 2)
  65.             {
  66.                 notas2 = Convert.ToInt32(valorMonetario) / 2;
  67.                 valorMonetario -= notas2 * 2;
  68.             }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.             //Parte que conta as moedas
  75.             if (valorMonetario >= 1)
  76.             {
  77.                 moedas1 = Convert.ToInt32(valorMonetario) / 1;
  78.                 valorMonetario -= moedas1 * 1;
  79.             }
  80.  
  81.             if (totalMoedas >= 50)
  82.             {
  83.                 moedas50 = Convert.ToInt32(totalMoedas) / 50;
  84.                 totalMoedas -= moedas50 * 50;
  85.             }
  86.  
  87.             if (totalMoedas >= 25)
  88.             {
  89.                 moedas25 = Convert.ToInt32(totalMoedas) / 25;
  90.                 totalMoedas -= moedas25 * 25;
  91.             }
  92.  
  93.             if (totalMoedas >= 10)
  94.             {
  95.                 moedas10 = Convert.ToInt32(totalMoedas) / 10;
  96.                 totalMoedas -= moedas10 * 10;
  97.             }
  98.  
  99.             if (totalMoedas >= 5)
  100.             {
  101.                 moedas5 = Convert.ToInt32(totalMoedas) / 5;
  102.                 totalMoedas -= moedas5 * 5;
  103.             }
  104.  
  105.             if (totalMoedas >= 1)
  106.             {
  107.                 moedas01 = Convert.ToInt32(totalMoedas) / 1;
  108.                 totalMoedas -= moedas01 * 1;
  109.             }
  110.  
  111.  
  112.             Console.WriteLine("NOTAS:");
  113.             Console.WriteLine(notas100 + " nota(s) de R$ 100.00");
  114.             Console.WriteLine(notas50 + " nota(s) de R$ 50.00");
  115.             Console.WriteLine(notas20 + " nota(s) de R$ 20.00");
  116.             Console.WriteLine(notas10 + " nota(s) de R$ 10.00");
  117.             Console.WriteLine(notas5 + " nota(s) de R$ 5.00");
  118.             Console.WriteLine(notas2 + " nota(s) de R$ 2.00");
  119.  
  120.             Console.WriteLine("MOEDAS:");
  121.             Console.WriteLine(moedas1 + " moeda(s) de R$ 1.00");
  122.             Console.WriteLine(moedas50 + " moeda(s) de R$ 0.50");
  123.             Console.WriteLine(moedas25 + " moeda(s) de R$ 0.25");
  124.             Console.WriteLine(moedas10 + " moeda(s) de R$ 0.10");
  125.             Console.WriteLine(moedas5 + " moeda(s) de R$ 0.05");
  126.             Console.WriteLine(moedas01 + " moeda(s) de R$ 0.01");
  127.         }
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment