Повторения с цикли -While-Loop домашна зад 3 Почивка
Уважаеми колеги нямам идея кое не е вярно на примерният Вход/Изход всичко ми е коректно , но ми дава 0 от 100, всякакви съвети са ми полезни , ето го моя код :
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 PriceEx = double.Parse(Console.ReadLine());
double AvMoney= double.Parse(Console.ReadLine());
string transact = string.Empty;
double totalSave = 0.0;
int countSp = 0;
int countSv = 0;
totalSave = AvMoney;
while (true)
{
transact = Console.ReadLine();
double amount = double.Parse(Console.ReadLine());
switch (transact)
{
case "save":
{
totalSave = totalSave+amount;
countSv++;
if (totalSave >= PriceEx)
{
Console.WriteLine("You saved the money for {0} days.", countSv+countSp);
break;
}
break;
}
case "spend":
{
totalSave = AvMoney-amount;
if (totalSave <= 0)
totalSave = 0;
countSp++;
if (countSp > 4)
{
Console.WriteLine("You can't save the money.");
Console.WriteLine(countSp);
break;
}
break;
}
}
}
}
}
}
има прогрес 77/100
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 PriceEx = double.Parse(Console.ReadLine());
double AvMoney= double.Parse(Console.ReadLine());
string transact = string.Empty;
double totalSave = 0.0;
int countSp = 0;
int countSv = 0;
totalSave = AvMoney;
while (true)
{
transact = Console.ReadLine();
double amount = double.Parse(Console.ReadLine());
if(transact == "save")
{
totalSave = totalSave+amount;
countSv++;
if (totalSave >= PriceEx)
{
Console.WriteLine("You saved the money for {0} days.", countSv+countSp);
break;
}
}
else if(transact== "spend")
{
totalSave = AvMoney-amount;
if (totalSave <= 0)
totalSave = 0;
countSp++;
if (countSp > 4)
{
Console.WriteLine("You can't save the money.");
Console.WriteLine(countSp);
break;
}
}
}
}
}
}
Това е моето решение може да го разгледате
using System;
namespace Vacation
{
class Program
{
static void Main(string[] args)
{
double priceVacantin = double.Parse(Console.ReadLine());
double ownedMoney = double.Parse(Console.ReadLine());
int counterSpendDays = 0;
int counterDays = 0;
bool isThereEnoughMoney = true;
while(ownedMoney<priceVacantin)
{
string action = Console.ReadLine();
double moneyCash = double.Parse(Console.ReadLine());
counterDays++;
if (action=="spend")
{
ownedMoney -= moneyCash;
counterSpendDays++;
if(moneyCash>ownedMoney)
{
ownedMoney = 0;
}
if (counterSpendDays==5)
{
Console.WriteLine("You can't save the money.");
Console.WriteLine($"{counterDays}");
isThereEnoughMoney = false;
break;
}
}
else if (action=="save")
{
ownedMoney += moneyCash;
counterSpendDays = 0;
}
}
if (isThereEnoughMoney==true)
{
Console.WriteLine($"You saved the money for {counterDays} days.");
}
}
}
}
не ти се мисли върху моето .....Благодаря