Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vacation
- {
- class Program
- {
- static void Main(string[] args)
- {
- double moneyForVacation = double.Parse(Console.ReadLine());
- double moneyAvailable = double.Parse(Console.ReadLine());
- string action = "";
- double sum = 0;
- int spendCounter = 0;
- int counter = 0;
- while (true)
- {
- action = Console.ReadLine();
- if (action == "spend")
- {
- sum = double.Parse(Console.ReadLine());
- counter++;
- spendCounter++;
- if (spendCounter == 5)
- {
- Console.WriteLine("You can't save the money." + "\r\n" + "{0}", spendCounter);
- break;
- }
- if (moneyAvailable < sum || moneyAvailable < 0)
- {
- moneyAvailable = 0;
- }
- else
- {
- moneyAvailable -= sum;
- }
- }
- else if (action == "save")
- {
- counter++;
- spendCounter = 0;
- sum = double.Parse(Console.ReadLine());
- moneyAvailable += sum;
- }
- if (moneyAvailable >= moneyForVacation)
- {
- Console.WriteLine("You saved the money for {0} days.", counter);
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement