Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //using System.Collections.Generic;
- //using System.Linq;
- namespace _3._Vacation
- {
- class Program
- {
- static void Main(string[] args)
- {
- double neededMoney = double.Parse(Console.ReadLine());
- double ownedMoney = double.Parse(Console.ReadLine());
- int brspend = 0;
- int brall = 0;
- //double sumSpendings = 0; Нямаме нужда от тази и от следващите 5 променливи.
- //double sumSavings = 0;
- //List<double> spendings = new List<double>();
- //List<double> savings = new List<double>();
- //double moneyAfterSpendings = 0;
- //double moneyAfterSavings = 0;
- while (ownedMoney < neededMoney && brspend < 5) // Нужен ни е while цикъл с тези 2 условия, а при теб е for цикъл, който ти въртиш до int.MaxValue, което не е правилно.
- {
- brall++; // Можем да увеличаваме общия брой дни само тук, вместо на 2 места в двете проверки.
- string action = Console.ReadLine();
- double sum = double.Parse(Console.ReadLine());
- if (action.Equals("spend"))
- {
- //spendings.Add(sum);
- //sumSpendings = spendings.Sum();
- //brall++;
- //moneyAfterSpendings = ownedMoney - sumSpendings;
- brspend++;
- ownedMoney -= sum; // От спестените пари изваждаме въведената от конзолата сума.
- //if (moneyAfterSpendings <= 0)
- if (ownedMoney <= 0) // Проверяваме с ownedMoney, нямаме нужда от допълнителни променливи.
- {
- ownedMoney = 0;
- }
- }
- else if (action.Equals("save"))
- {
- //savings.Add(sum);
- //sumSavings = savings.Sum();
- //brall++;
- //moneyAfterSavings = sumSavings + moneyAfterSpendings;
- brspend = 0;
- ownedMoney += sum; // Към спестените пари прибавяме въведената от конзолата сума.
- //if (moneyAfterSavings >= neededMoney)
- if (ownedMoney >= neededMoney) // Отново проверяваме с ownedMoney, като и тук нямаме нужда от допълнителни променливи.
- {
- Console.WriteLine("You saved the money for {0} days.", brall);
- break;
- }
- }
- if (brspend == 5)
- {
- Console.WriteLine("You can't save the money.");
- Console.WriteLine(brall);
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment