谁能告诉我如何在 C# 中输入两个输入值

本文关键字:输入 两个 告诉我 | 更新日期: 2023-09-27 18:33:11

我无法为我的一个作业在 C# 中输入两个不同的输入值。它似乎不想用我设置它的方式进行调试。

  • 输出值为:英里每加仑
  • 输入值为:里程行驶,使用的加仑气体
到目前为止,这就是我设置它

的方式,它仍然对我不起作用。

static void Main(string[] args)
{
    float milespergallon, milestraveled, gallonsofgasused;
    string textLine;
    Console.Write("What is the total miles traveled and gallons of gas used? ");
    textLine = Console.ReadLine();  // read in text from console
    milestraveled and gallonsofgasused = float.Parse(textLine); // convert text into floating point
    milespergallon =  miles / gallons;    // calculate mpg = miles / gallons
    Console.Write("Miles Per Gallon: ");
    Console.WriteLine(milespergallon.ToString());// Output miles per gallon to console
    Console.ReadLine();                  // Wait for return key press
}

谁能告诉我如何在 C# 中输入两个输入值

double milespergallon, milestraveled, gallonsofgasused;    // don't fiddle with float
string textLine;
Console.Write("What is the total miles traveled? ");
textLine = Console.ReadLine();  // read in text from console
milesTraveled = double.Parse(textLine);
Console.Write("What is the total gallons of gas used? ");
textLine = Console.ReadLine();  // read in text from console
gallonsOfGasUsed= double.Parse(textLine);
...