I created a Class That takes gallons of fuel and Mileage then gives the total Mpg.
I need it to give the mpg after both the gallons and mileage are entered and also the total Mpg.
Public Class MilesPerGallon
Private mileCount As Integer
Private gallonCount As Integer
Private mileTotal As Integer
Private gallonTotal As Integer
Public Sub InputMiles()
Console.Write("Enter the miles travelled, enter a negative number to finish: ")
Dim miles As Double = Console.ReadLine()
While miles >= 0
mileTotal += miles
mileCount += 1
Console.Write("Enter the miles travelled, enter a negative number to finish: ")
miles = Console.ReadLine
End While
End Sub
Public Sub InputGallons()
Console.Write("Enter the gallon amount used, enter a negative number to end: ")
Dim gallons As Double = Console.ReadLine()
If gallons = 0 Then
Console.WriteLine("Gallons entered must be greater than 0.")
Exit Sub
End If
While gallons >= 0
gallonTotal += gallons
gallonCount += 1
Console.Write("Enter the gallon amount used, enter a negative number to end: ")
gallons = Console.ReadLine
End While
End Sub
Public Sub DisplayAverage()
Console.WriteLine("=============================================================" & _
vbCrLf & "Averages:" & vbCrLf & "======================================================")
If gallonCount > 0 Then
Dim milesPerGallon As Double = mileTotal / gallonTotal
milesPerGallon = Math.Round(milesPerGallon, 2)
Console.WriteLine("There was {0} miles travelled and {1} gallons used.", _
mileTotal, gallonTotal)
Console.WriteLine("That averages out to {0:F3}", milesPerGallon & " miles per gallon.")
Else
Console.WriteLine("Either you entered zero for gallons or nothing was entered.")
End If
Console.ReadLine()
End Sub
End Class
Here is the Main
Module Module1
Sub Main()
Dim Honda As New MilesPerGallon()
Honda.InputMiles()
Honda.InputGallons()
Honda.DisplayAverage()
End Sub
End Module
Any Help Would Be Truly appreciated.