Проблем със 04. Vacation задача.
using System;
using System.Text;
namespace _03.ExamPreparation
{
public class Program
{
public static void Main()
{
double moneyForTrip = double.Parse(Console.ReadLine());
double moneyHave = double.Parse(Console.ReadLine());
double moneySpendOrSave = 0;
int daysCounter = 0;
string saveOrSpend = string.Empty;
string result = string.Empty;
string result2 = string.Empty;
while (moneyHave <= 0)
{
daysCounter++;
saveOrSpend = Console.ReadLine();
moneySpendOrSave = double.Parse(Console.ReadLine());
switch (saveOrSpend)
{
case "save":
Math.Abs(moneyHave += moneySpendOrSave);
break;
case "spend":
Math.Abs(moneyHave -= moneySpendOrSave);
break;
}
if (moneyHave >= moneyForTrip)
{
result = $"You saved the money for {daysCounter} days.";
break;
}
else if (moneyHave <= 0)
{
result = "You can't save the money.";
result2 = $"{daysCounter}";
break;
}
}
Console.WriteLine(result);
Console.WriteLine(result2);
}
}
}
Това ми е кода проблема е че цикъла спира на последната проверка как може да го оправя.