задача Вендинг
Здрвейте,
не мога да разбера защо гърми парсването на coin когато използвам 0.5 , възможно и да е от точката или греша друго
using System;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
string coin = Console.ReadLine();
double total = 0;
string orders = "";
while (coin != "start")
{
double curCoin = Double.Parse(coin);
total += curCoin;
if (curCoin != 0.1 && curCoin!= 0.2 && curCoin !=0.5 && curCoin!=1 && curCoin!= 2)
{
Console.WriteLine($"Cannot accept {curCoin}");
total -= curCoin;
}
coin = Console.ReadLine();
}
while (orders!="End" && total>=0)
{
orders = Console.ReadLine();
if (orders != "Nuts" && orders != "Water" && orders != "Crisp" && orders != "Soda" && orders != "Coke")
{
Console.WriteLine("Invalid product");
}
if (orders == "Nuts" && total >= 2.0)
{
Console.WriteLine($"Purchased {orders}");
total -= 2.0;
}
else
{
Console.WriteLine("Sorry, not enough money");
}
if (orders == "Water" && total >= 0.7)
{
total -= 0.7;
}
else
{
Console.WriteLine("Sorry, not enough money");
}
if (orders == "Crisp" && total >= 1.5)
{
total -= 1.5;
}
else
{
Console.WriteLine("Sorry, not enough money");
}
if (orders == "Soda" && total >= 0.8)
{
total -= 0.8;
}
else
{
Console.WriteLine("Sorry, not enough money");
}
if (orders == "Coke" && total >= 1.0)
{
total -= 1.0;
}
else
{
Console.WriteLine("Sorry, not enough money");
}
}
if (orders == "End" )
{
Console.WriteLine($"Change: {total:f2}");
}
}
}
}