Advertisement
Guest User

Untitled

a guest
Jun 8th, 2020
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02._Report_System
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int expectedSUm = int.Parse(Console.ReadLine());
  10.             string command = null;
  11.             int transactionsCounter = 0;
  12.             int cash = 0;
  13.             int transactionCash = 0;
  14.             int card = 0;
  15.             int transactionCard = 0;
  16.  
  17.             while ((command = Console.ReadLine()) != "End" && cash + card < expectedSUm)
  18.             {
  19.                 int itemsPrice = int.Parse(command);
  20.  
  21.                 //По условие се редуват:  
  22.                 if (transactionsCounter++ % 2 == 0)//първо плащане в брой
  23.                 {
  24.                     if (itemsPrice > 100)
  25.                     {
  26.                         Console.WriteLine($"Error in transaction!");
  27.                     }
  28.                     else
  29.                     {
  30.                         transactionCash++;
  31.                         cash += itemsPrice;
  32.                         Console.WriteLine($"Product sold!");
  33.                     }
  34.  
  35.                 }
  36.                 else //след това чрез кредитна карта
  37.                 {
  38.                     if (itemsPrice < 10)
  39.                     {
  40.                         Console.WriteLine($"Error in transaction!");
  41.                     }
  42.                     else
  43.                     {
  44.                         transactionCard++;
  45.                         card += itemsPrice;
  46.                         Console.WriteLine($"Product sold!");
  47.                     }
  48.                 }
  49.             }
  50.  
  51.             if (command == "End")
  52.             {
  53.                 Console.WriteLine($"Failed to collect required money for charity.");
  54.             }
  55.             else
  56.             {
  57.                 double totalSumCash = cash * 1.0 / transactionCash;
  58.                 double totalSumCard = card * 1.0 / transactionCard;
  59.                 Console.WriteLine($"Average CS: {totalSumCash:F2}");
  60.                 Console.WriteLine($"Average CC: {totalSumCard:F2}");
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement