-3

課題の 1 つで 2 つの異なる入力値を 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 に答える