-2
私の質問は、以下のコードを数字だけを受け入れるようにするにはどうすればいいですか?C#で値を乗算する方法は?
Console.WriteLine("Please enter the number of tickets sold for movie x or 1 to exit now!");
int adult = Convert.ToInt32(Console.ReadLine());
int total1 = 30 * adult;
if (adult >= 5 && adult <= 30)
{
Console.WriteLine("The total cost for the adults tickets is : {0}", total1);
}
else if (adult == 1)
{
Environment.Exit(0);
}
else
{
Console.WriteLine("Error for adults");
}
Console.WriteLine("Please enter the number of tickets sold for z or y to exit now!");
int child = Convert.ToInt32(Console.ReadLine());
int total2 = 20 * child;
if (child >= 5 && child <= 30)
{
Console.WriteLine("The total cost for the child tickets is : {0}", total2);
}
else if (child == 1)
{
Environment.Exit(0);
}
else
{
Console.WriteLine("Error for child");
}
int finTotal = total1 + total2;
Console.WriteLine("The cost of all the tickets together is : {0}", finTotal);
Console.ReadLine();
フォーマットを使用してください –