Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace tester1
- {
- using System;
- public class StartUp
- {
- public static void Main(string[] args)
- {
- double budget = double.Parse(Console.ReadLine());
- int rejectionCount = 1;
- string lastProduct = string.Empty;
- double productPrice = 0;
- bool areGood = true;
- while (true)
- {
- string product = Console.ReadLine();
- if (product == "Going home.")
- {
- break;
- }
- productPrice = double.Parse(Console.ReadLine());
- if (productPrice > budget)
- {
- if (product == lastProduct)
- {
- rejectionCount++;
- }
- else
- {
- rejectionCount = 1;
- }
- Console.WriteLine($"You can't have {product} today!");
- }
- else
- {
- budget -= productPrice;
- }
- if (rejectionCount == 3)
- {
- Console.WriteLine("End of the walk!");
- areGood = false;
- break;
- }
- lastProduct = product;
- }
- if (areGood)
- {
- Console.WriteLine("Good kids! We should go out more often!");
- Console.WriteLine($"Money left: {budget:F2}lv.");
- }
- else
- {
- Console.WriteLine("Not so good kids! We are never going out again!");
- Console.WriteLine($"You have {budget:F2}lv and {lastProduct} costs {productPrice:F2}lv.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement