Грешки в judge? 7 Vending Machine
Здравейте, хора :)
Накратко, правя лап упражненията от C# Fundamentials и съм на задача 7 Vending Machine.
Solution #13884301 by VesselinTonchev for problem 07. Vending Machine
Давам ми 100/100, в същото време ми изкарва един куп грешки и пак в същото време, тези грешки са грешни. Пример:
Test input:
1
Start
Nuts
Coke
End
Expected output:
Sorry, not enough money
Purchased coke
Change: 0.00 ----------------който изобщо не трябва да е верен
Your output:
Purchased nuts
Sorry, not enough money
Change: 1.00
Change: 1.00 -------------------- трябва да си е верен.
using System;
namespace Vending_machine__2
{
class Program
{
static void Main(string[] args)
{
string input = Console.ReadLine();
//double coinInserted = double.Parse(Console.ReadLine());
//VARIABLES
double inputToNum = double.Parse(input);
double sum = 0;
double price = 0;
bool end = false;
double tempPrice = 0;
double totalPrice = 0;
//VARIABLES
//COIN CHECKER
while (input != "Start")
{
inputToNum = double.Parse(input);
if (inputToNum != 0.1 && inputToNum != 0.2 &&
inputToNum != 0.5 && inputToNum != 1 && inputToNum != 2)
{
Console.WriteLine($"Cannot accept {input}");
input = Console.ReadLine();
//inputToNum = double.Parse(input);
continue;
}
sum += inputToNum;
input = Console.ReadLine();
//COIN CHECKER
}
//PURCHASING PRODUCTS
if (input == "Start")
{
while (input != "End")
{
//PRODUCT BASE
switch (input)
{
case "Nuts":
price = 2.0;
Console.WriteLine("Purchased nuts");
break;
case "Water":
price = 0.7;
Console.WriteLine("Purchased water");
break;
case "Crisps":
price = 1.5;
Console.WriteLine("Purchased crisps");
break;
case "Soda":
price = 0.8;
Console.WriteLine("Purchased soda");
break;
case "Coke":
price = 1.0;
Console.WriteLine("Purchased coke");
break;
case "Start":
break;
default:
Console.WriteLine("Invalid product");
break;
}
//PRODUCT BASE
tempPrice = price;
totalPrice += price;
if (totalPrice > sum)
{
totalPrice -= price;
Console.WriteLine("Sorry, not enough money");
Console.WriteLine($"Change: {sum - totalPrice:f2}");
end = true;
if (end)
{
break;
}
}
input = Console.ReadLine();
}
}
//PURCHASING PRODUCTS
Console.WriteLine($"Change: {sum - totalPrice:f2}");
}
}
}