Advertisement
Guest User

Untitled

a guest
Jun 8th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 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.             int totalSum = cash + card;
  17.  
  18.             while ((command = Console.ReadLine()) != "End" && totalSum < expectedSUm)
  19.             {
  20.                 int itemsPrice = int.Parse(command);
  21.  
  22.                 //По условие се редуват:  
  23.                 if (transactionsCounter % 2 == 0)//първо плащане в брой
  24.                 {
  25.                     if (itemsPrice => 100)
  26.                     {
  27.                         Console.WriteLine($"Error in transaction!"); // Ако продуктът надвишава 100лв., за него не може да се плати в брой
  28.                     }
  29.                     else
  30.                     {
  31.                         transactionCash++;
  32.                         itemsPrice += cash;
  33.                         Console.WriteLine($"Product sold!");
  34.                     }
  35.  
  36.                 }
  37.                 else //след това чрез кредитна карта
  38.                 {
  39.                     if (itemsPrice <= 10)
  40.                     {
  41.                         Console.WriteLine($"Error in transaction!"); //Ако продуктът е на цена под 10лв., за него не може да се плати с кредитна карта
  42.                     }
  43.                     else
  44.                     {
  45.                         transactionCard++;
  46.                         itemsPrice += card;
  47.                         Console.WriteLine($"Product sold!");
  48.                     }
  49.                 }
  50.  
  51.                
  52.  
  53.             }
  54.  
  55.             if (command == "End")
  56.             {
  57.                 Console.WriteLine($"Failed to collect required money for charity.");
  58.             }
  59.             else
  60.             {
  61.                 //  Обща сума в брой => 63 + 78 = 141 Средно в брой => 141 / 2 = 70.50
  62.                 double totalSumCash = cash / transactionCash;
  63.                 // Общо кредитни карти => 256 + 317 = 573 Средно кредитни карти => 573 / 2 = 286.5
  64.                 double totalSumCard = card / transactionCard;
  65.                 Console.WriteLine($"Average CS: {totalSumCash:F2}");
  66.                 Console.WriteLine($"Average CC: {totalSumCard:F2}");
  67.             }
  68.  
  69.            
  70.  
  71.         }
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement