Advertisement
NelIfandieva

Test_31Oct2019_Problem03_CharityCollector

Oct 29th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp210
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             decimal desiredAmount = decimal.Parse(Console.ReadLine());
  11.             decimal totallyCollected = 0.00M;
  12.             string command = "";
  13.  
  14.             while(command != "End" && totallyCollected < desiredAmount)
  15.             {
  16.                 command = Console.ReadLine();
  17.  
  18.                 if(command == "End" || totallyCollected >= desiredAmount)
  19.                 {
  20.                     break;
  21.                 }
  22.                 decimal incomingAmount;
  23.                 bool commandIsDecimal = decimal.TryParse(command, out incomingAmount);
  24.  
  25.                 if(commandIsDecimal)
  26.                 {
  27.                     totallyCollected += incomingAmount;
  28.                 }
  29.             }
  30.  
  31.             if(totallyCollected >= desiredAmount)
  32.             {
  33.                 Console.Write("We collected the entire amount of {0}.", totallyCollected);
  34.             }
  35.             else
  36.             {
  37.                 Console.Write("We collected {0} - {1} less than the necessary amount.", totallyCollected, desiredAmount - totallyCollected);
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement