Advertisement
silvana1303

report system

Apr 13th, 2020
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2.  
  3. namespace whileloop
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int neededSum = int.Parse(Console.ReadLine());
  10.  
  11.             string command = Console.ReadLine();
  12.  
  13.            
  14.             int moneyCard = 0;
  15.             int moneyCash = 0;
  16.             int cardCount = 0;
  17.             int cashCount = 0;
  18.             int count = 0;
  19.  
  20.             while (true)
  21.             {
  22.                 if (command == "End" )
  23.                 {
  24.                     Console.WriteLine("Failed to collect required money for charity.");
  25.                     break;
  26.                 }
  27.  
  28.                
  29.                 count++;
  30.  
  31.                
  32.  
  33.                 int sum = int.Parse(command);
  34.  
  35.                 if (count % 2 == 1 )
  36.                 {
  37.                     if (sum <= 100)
  38.                     {
  39.                         moneyCash += sum;
  40.                         cashCount++;
  41.                         Console.WriteLine("Product sold!");
  42.                     }
  43.                     else
  44.                     {
  45.                         Console.WriteLine("Error in transaction!");
  46.                     }
  47.                 }
  48.                 if(count % 2 == 0)
  49.                 {
  50.                     if (sum > 10 )
  51.                     {
  52.                         moneyCard +=sum;
  53.                         cardCount++;
  54.                         Console.WriteLine("Product sold!");
  55.                     }
  56.                     else
  57.                     {
  58.                         Console.WriteLine("Error in transaction!");
  59.                     }
  60.                 }
  61.  
  62.                 int money = moneyCard + moneyCash;
  63.  
  64.                 if (money >= neededSum)
  65.                 {
  66.                     Console.WriteLine($"Average CS: {1.0*moneyCash/cashCount:F2}");
  67.                     Console.WriteLine($"Average CC: {1.0*moneyCard / cardCount:F2}");
  68.                     break;
  69.                 }
  70.  
  71.                 command = Console.ReadLine();
  72.  
  73.             }
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement