Enter the miles driven, use -1 to end:
Enter the gallons :
The miles / gallon for this tank was
Enter the miles driven, use -1 to end:
Enter the gallons used (-1 to end) :
The miles / gallon for this tank was
Enter the miles driven, use -1 to end:
Enter the gallons used (-1 to end) :
The miles / gallon for this tank was
Enter the miles driven, use -1 to end: -1
The overall average miles/gallon was
I tried to solve this above probem but i cant figure out where i m going wrong or what to do next .. can anyone please help me out with it
Public Sub OverallAverage()
Dim miles, gallons As Double
Dim totalGallons As Double = 0
Dim totalMiles As Double = 0
Dim tank As Double = 0
Dim average As Double = 0
Console.Write("Enter the miles driven, use -1 to end: ")
gallons = Console.ReadLine()
While miles <> -1
Console.Write("Enter the gallons: ")
gallons = Console.ReadLine()
tank = miles / gallons
Console.WriteLine("The miles / gallon for this tank was " & tank)
Console.WriteLine("Enter the miles driven, use -1 to end: ")
miles = Console.ReadLine()
totalGallons = totalGallons + gallons
totalMiles = totalMiles + miles
End While
average = totalMiles / totalGallons
Console.Write("The overall average miles/gallon was: " & average)
End Sub