Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace whileloop
- {
- class Program
- {
- static void Main(string[] args)
- {
- int neededSum = int.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- int moneyCard = 0;
- int moneyCash = 0;
- int cardCount = 0;
- int cashCount = 0;
- int count = 0;
- while (true)
- {
- if (command == "End" )
- {
- Console.WriteLine("Failed to collect required money for charity.");
- break;
- }
- count++;
- int sum = int.Parse(command);
- if (count % 2 == 1 )
- {
- if (sum <= 100)
- {
- moneyCash += sum;
- cashCount++;
- Console.WriteLine("Product sold!");
- }
- else
- {
- Console.WriteLine("Error in transaction!");
- }
- }
- if(count % 2 == 0)
- {
- if (sum > 10 )
- {
- moneyCard +=sum;
- cardCount++;
- Console.WriteLine("Product sold!");
- }
- else
- {
- Console.WriteLine("Error in transaction!");
- }
- }
- int money = moneyCard + moneyCash;
- if (money >= neededSum)
- {
- Console.WriteLine($"Average CS: {1.0*moneyCash/cashCount:F2}");
- Console.WriteLine($"Average CC: {1.0*moneyCard / cardCount:F2}");
- break;
- }
- command = Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement