I need help writing a program that prompts the user for five grades and then provides the user with an average for all grades entered.

Module Module1

    Sub Main()
        'Declare Array called AverageGrades with 5 Elements
        Dim Grades(5) As String

        'Write array elements to screen using For loop
        Dim index As Integer

        'Write average 
        Dim Average(1) As Integer

        'Loop to have user input array values dynamically
        For index = 0 To 4 Step 1
            Console.Write("Enter the " & index + 1 & " received grade:")
            Grades(index) = Console.ReadLine()

        For (**** Not sure)))*** need average!

            Next

            'Loop to print out array values
            Console.WriteLine(vbCrLf & "These are the grades you entered.")
            For index = 0 To 4 Step 1
                Console.Write(Grades(index) & vbCrLf)
            Next
            Console.Write(vbCrLf & "Press Enter key to exit")
            Console.ReadLine()



    End Sub

End Module
Sub Main()

        Dim arrGrades(4) As Integer
        Dim intTotal As Integer = 0

        'Get input
        For intIndex = 0 To 4
            Console.Write("Enter the " & intIndex + 1 & " received grade: ")
            arrGrades(intIndex) = CInt(Console.ReadLine())
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        'Display Grades
        For intIndex = 0 To 4
            Console.WriteLine("Grade {0} : {1}", (intIndex + 1), arrGrades(intIndex).ToString)
            intTotal += arrGrades(intIndex)
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        Console.WriteLine("Average Grade : {0}", FormatNumber(intTotal / 5, 2))
        Console.WriteLine("Press Enter key to exit")

        Console.ReadLine()

    End Sub

that worked great thanks. alot of your codes aren't at my level yet but its cool =)

Im glad it worked for ya; dont forget to mark the thread as solved. I attempted to keep the coding similar to your original example as to not jump ahead of your level but if you need any explaination of what I did, just ask. I think the only differences were converting datatypes properly and the formatting for display.

Added comments

Sub Main()

        Dim arrGrades(4) As Integer
        Dim intTotal As Integer = 0

        'Get input
        For intIndex = 0 To 4
            Console.Write("Enter the " & intIndex + 1 & " received grade: ")

            'Input values are text so I am converting the text of
            'the grade entered into a numeric datatype (integer) for 
            'future calculation and storing the value into the array.
            arrGrades(intIndex) = CInt(Console.ReadLine())
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        'Display Grades
        For intIndex = 0 To 4

            'Use of the placeholders simply avoids string concatenation
            'The first placeholder {0} is the intIndex +1
            'The second is the index of where the grade is being
            'stored in the array. The .ToString converts it from the
            'the numeric datatype (integer) back into a string for display.
            Console.WriteLine("Grade {0} : {1}", (intIndex + 1), arrGrades(intIndex).ToString)

            ' The below is just adding all the grades up into a total
            intTotal += arrGrades(intIndex)
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        ' For the average I'm just dividing the total by 5
        ' The format number is a way to make sure that 
        ' that you dont get an answer that has more then
        ' 2 places passed the decimal point displayed.
        'The formatnumber method at the same time is 
        'converting the numeric value into a string.
        Console.WriteLine("Average Grade : {0}", FormatNumber(intTotal / 5, 2))

        Console.WriteLine("Press Enter key to exit")
        Console.ReadLine()
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.