Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace zad7
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- double Sum = 0;
- while (input != "Start")
- {
- double coins = double.Parse(input);
- if (coins == 0.1)
- {
- Sum += 0.1;
- } else if (coins == 0.2) {
- Sum += 0.2;
- } else if (coins == 0.5)
- {
- Sum += 0.5;
- } else if (coins == 1)
- {
- Sum += 1;
- } else if (coins == 2)
- {
- Sum += 2;
- } else
- {
- Console.WriteLine($"Cannot accept {coins:f1}");
- }
- input = Console.ReadLine();
- }
- input = Console.ReadLine();
- while (input != "End")
- {
- double testSum = Sum;
- if (input == "Nuts")
- {
- testSum -= 2;
- if (testSum < 0)
- {
- Console.WriteLine("Sorry, not enough money");
- } else
- {
- Console.WriteLine("Purchased nuts");
- Sum = testSum;
- }
- } else if (input == "Water")
- {
- testSum -= 0.7;
- if (testSum < 0)
- {
- Console.WriteLine("Sorry, not enough money");
- } else
- {
- Console.WriteLine("Purchased water");
- Sum = testSum;
- }
- } else if (input == "Crisps")
- {
- testSum -= 1.5;
- if (testSum < 0)
- {
- Console.WriteLine("Sorry, not enough money");
- } else
- {
- Console.WriteLine("Purchased crisps");
- Sum = testSum;
- }
- } else if (input == "Soda")
- {
- testSum -= 0.8;
- if (testSum < 0)
- {
- Console.WriteLine("Sorry, not enough money");
- } else
- {
- Console.WriteLine("Purchased soda");
- Sum = testSum;
- }
- } else if (input == "Coke")
- {
- testSum -= 1;
- if (testSum < 0)
- {
- Console.WriteLine("Sorry, not enough money");
- } else
- {
- Console.WriteLine("Purchased coke");
- Sum = testSum;
- }
- } else
- {
- Console.WriteLine("Invalid product");
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Change: {Sum:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement