Здравствуйте. У меня сейчас проблемы с моим проектом.В настоящее время у меня возникают проблемы с моей консольной программой, где я беру вводимые пользователем данные (из которых есть десятичные дроби), а затем использую их в операторах if els, а затем, наконец, делаю последнюю математику для расчета стоимости билета.
iя искал способы, как я мог бы это исправить, но в течение последних нескольких часов я не смог найти исправление.
я пытался использовать строки, inter, var и boolen для хранения цены, но когдадоходит до финальной математики, чтобы вычислить стоимость, только ошибки не дают мне ошибки.
Я думаю, что исправлением было бы изменение способа, которым пользователь выбирает билет, который он хочет, но я не могу выработатьспособ, позволяющий им выбирать из меню билетов, при этом значения цен, назначенные для их ввода, говорят:
Int family = 39.90
, а затем используют это каким-то образом, чтобы дать пользователям возможность ввести значение, основанное на том, что яState.
Может кто-нибудь предложить способ, которым я мог бы сделать это иначе или решение моей текущей ошибки деления / FormatException?
также приветствуются любые другие советы по формату ect, приветствуется любая критика.
Текущий код консоли:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace The_Admission_Price_Calculator
{
class Program
{
static void Main(string[] args)
{
Action<string> cw = Console.WriteLine;
cw("Hello welcome to the WildLife park");
cw("We currently have 4 ticket options:");
cw("1: Famliy ticket(2 adults + 3 children) £39.90");
cw("2: Adult ticket £14.90");
cw("3: Child (under 16) £9.90");
cw("4: Senior (over 65) £7.00");
cw("Please input the price of the ticket you would like?");
cw("(EG if you want to child ticket please input 9.90, please also include the decimal place.");
cw("Input your the tickets price you would like to order now please.");
string Answer1;
int TicketCost1;
int TicketAmount1;
int TicketType1;
TicketType1 = Convert.ToInt32(Console.ReadLine());
if (TicketType1 == 39.90)
{
//int Famliy = 3990;
}
else if (TicketType1 == 9.90)
{
//int Child = 990;
}
else if (TicketType1 == 14.90)
{
//int Adult = 1490;
}
else if (TicketType1 == 7.00)
{
//int Senior = 700;
}
else
{
Console.WriteLine("you need to Input from the options, using the price of the ticket, with the decimal included.");
TicketType1 = Convert.ToInt32(Console.ReadLine());
}
cw("your choosen ticket is " + TicketType1 + ", how many tickets of this type would you like?");
TicketAmount1 = int.Parse(Console.ReadLine());
//Rember to Add /100 to the final sum, so that the output is in decimals.
TicketCost1 = TicketAmount1 * TicketType1;
cw("With the choosen amount of tickets of " +TicketAmount1+ " this will cost £" +TicketCost1+" ");
cw("Is this correct? (YES OR NO");
Answer1 = Console.ReadLine();
if (Answer1 == "YES")
{
cw("Tickets are printing now.");
}
if (Answer1 == "NO")
{
cw("Please reselect what tickets you would like");
//code here
}
else
{
cw("You have not entred a vaild asnswer please Input YES Or not in captials");
Answer1 = Console.ReadLine();
//core here
}
Console.ReadKey();
}
}
}