Advertisement
AngelVasilev

Report System

Dec 27th, 2019
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace While___Report_System
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int moneyNeeded = int.Parse(Console.ReadLine());
  10.             string input = Console.ReadLine();
  11.             int cashCounter = 0;
  12.             int creditCardCounter = 0;
  13.             int counter = 0;
  14.             double totalSum = 0;
  15.             double sumByCard = 0;
  16.             double sumByCash = 0;
  17.             bool hasEnoughMoney = false;
  18.  
  19.             while (input != "End")
  20.             {
  21.                 int priceMoney = int.Parse(input);
  22.                 if (counter % 2 == 0)
  23.                 {
  24.                     if (priceMoney > 100)
  25.                     {
  26.                         Console.WriteLine("Error in transaction!");
  27.                     }
  28.                     else
  29.                     {
  30.                         Console.WriteLine("Product sold!");
  31.                         sumByCash += priceMoney;
  32.                         cashCounter++;
  33.                     }
  34.                 }
  35.                 else
  36.                 {
  37.                     if (priceMoney < 10)
  38.                     {
  39.                         Console.WriteLine("Error in transaction!");
  40.                     }
  41.                     else
  42.                     {
  43.                         Console.WriteLine("Product sold!");
  44.                         sumByCard += priceMoney;
  45.                         creditCardCounter++;
  46.                     }
  47.                 }
  48.                 totalSum = sumByCard + sumByCash;
  49.                 if (totalSum >= moneyNeeded)
  50.                 {
  51.                     hasEnoughMoney = true;
  52.                     break;
  53.                 }
  54.                 input = Console.ReadLine();
  55.                 counter++;
  56.             }
  57.             if (hasEnoughMoney)
  58.             {
  59.                 Console.WriteLine($"Average CS: {sumByCash / cashCounter:F2}");
  60.                 Console.WriteLine($"Average CC: {sumByCard / creditCardCounter:F2}");
  61.             }
  62.             else
  63.             {
  64.                 Console.WriteLine($"Failed to collect required money for charity.");
  65.             }
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement