-3

我在为我的一项作业输入两个不同的输入值到 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
}
4

1 回答 1

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

...
于 2013-09-29T21:44:37.540 回答