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

时间:2013-09-29 20:47:40

标签: c#

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

  • 输出值为:Miles Per Gallon
  • 输入值为:Miles 旅行,使用加仑加仑

到目前为止,这是我设置它的方式,它仍然不适用于我。

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
}

1 个答案:

答案 0 :(得分:1)

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);

...