0
我正在研究一個C#應用程序,該應用程序應該輸入英里驅動和每加侖使用的汽油(整數),然後應用程序應計算並顯示每加侖獲得的英里數對於每輛坦克,並顯示爲每輛坦克獲得的每加侖英里數。我的問題是,標記控制方面「-1」不會停止運行程序,但是,IDE啓動了一個JIT調試器,並且我得到了一個Microsoft.NET框架異常MileageDriven.exe [732]。Visual Studio C#2010練習第四版
我可以得到一些幫助,因爲我不想超越這個練習,因爲未來的課程將建立在最後一課之上。提前致謝。 :)
using System;
public class MileagedrivenTest
{
public static void Main(string[] args)
{
Mileage driverMileage = new Mileage("Driver log");
driverMileage.DisplayMessage();
driverMileage.DetermineMileagePerGallon();
} // end main
} // end class MileageDrivenTest
// Fig. 1.1: MileageDriven.cs
// Mileage class that solves mileage per gallon problem
// using sentinel-controlled repetition
using System;
public class Mileage
{
public string Gallons { get; set; }
public Mileage (string name)
{
Gallons = name;
}
public void DisplayMessage()
{
Console.WriteLine("Welcome to the mileage log for\n{0}\n", Gallons);
} // end method DisplayMessage
//determine the average mileage for gallon per tank of gas
public void DetermineMileagePerGallon()
{
int total = 0;
int mileage; // sum of miles driven
int gallons; // sum gallons used
double average;
int mileageCounter = 0;
Console.WriteLine("Enter mileage or -1 to quit: ");
mileage = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter gallons used: ");
gallons = Convert.ToInt32(Console.ReadLine());
while (mileage != -1)
{
mileage = total + mileage;
mileageCounter = mileageCounter + mileage;
Console.Write("Enter next miles driven or -1 to quit: ");
mileage = Convert.ToInt32(Console.ReadLine());
} // end while
if (mileageCounter != 0)
{
average = (double)total/mileageCounter;
Console.WriteLine("\nTotal of the {0} miles driven is {1} per tank is{}", mileageCounter, total);
Console.WriteLine("Average mile per gallon is {0}", average);
}
else
Console.WriteLine("No mileage entered");
}
}
很難知道我們如何能夠在不看任何代碼或異常幫助.. – 2012-03-29 07:13:08
確實,我會發布我寫的代碼。謝謝。只是一個瞬間。 – 2012-03-29 07:14:20
我試圖張貼代碼,但沒有骰子。我只是在學習這個網站。裸露在一起。 – 2012-03-29 07:18:19