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.

so what is your problem ? any errror with your code ? i think this question should have been in the .NET forum not here in the traditional VB forum.

No there really isn't a problem with the code I just need it to spit out miles travelled then gallons then summary of that then repeat until stopped and give a summary of the whole thing

Here try this...

Public Class MilesPerGallon
    Public Sub InputMiles()
        Dim miles As Double = 0

        While miles <= 0
            Console.Write("Enter the miles travelled: ")
            miles = Console.ReadLine
            If miles <= 0 Then
                Console.WriteLine("Gallons entered must be greater than 0.")
            End If
        End While

        InputGallons(miles)
    End Sub

    Private Sub InputGallons(ByVal miles As Double)
        Dim gallons As Double = 0
        While gallons <= 0
            Console.Write("Enter the gallon amount used: ")
            gallons = Console.ReadLine
            If gallons = 0 Then
                Console.WriteLine("Gallons entered must be greater than 0.")
            End If
        End While

        DisplayAverage(miles, gallons)
    End Sub

    Private Sub DisplayAverage(ByVal miles As Double, ByVal gallons As Double)
        Console.WriteLine("=============================================================" & _
        vbCrLf & "Averages:" & vbCrLf & "======================================================")

        Dim milesPerGallon As Double = miles / gallons
        milesPerGallon = Math.Round(milesPerGallon, 2)
        Console.WriteLine("There was {0} miles travelled and {1} gallons used.", _
                           miles, gallons)
        Console.WriteLine("That averages out to {0:F3}", milesPerGallon & " miles per gallon.")
    End Sub
End Class

in your module...

Sub Main()
        Dim Honda As New MilesPerGallon()
        Honda.InputMiles()
    End Sub
This article has been dead for over six months. Start a new discussion instead.