Good morning,

Can someone help me code this part of my assignment, it's been 24 hrs trying to do this.

Place student names and final mark into two, one- dimensional arrays. One array will be of String (for names), the other will be an array for real numbers (for marks)
Use the array to display:
Class Average
The number of students above the class average

THANKS!

Recommended Answers

All 6 Replies

Looking back over your posts you seem to be going around in circles. It looks like you've asked this question in different words before. Perhaps, showing all your code, what you're trying to accomplish, and what it's doing wrong and/or what it's not doing right, will get you more complete answers.

While you can learn alot from this site, that isn't its main goal. This site's main goal, from what I understand, is to fix problems people are having, mostly with code.

We also try to educate, as you might have noticed from the code snippet and tutorial portions of the forums.

I believe you both, but I don't have knowledge about one area of my assignment, and I am doing this course online. Sadly, help is scare, so I turned to this online community for help.

The part i don't have wisdom in applying is how to write my function to file so that I can read it back later.

This is the function I created to return a class average:

   Public Function ClassAverage(ByVal Grades As Decimal) As Decimal



    Dim FinalGrades() As Decimal = {76.5D, 63.4D, 45.4D, 94.5D, 81.3D, 66.2D, 68.6D}
            Dim sum As Decimal = 0

            For intCounter As Integer = 0 To FinalGrades.Length - 1
                sum += FinalGrades(intCounter)
            Next

            ClassAverage = (sum / FinalGrades.Length)

            Return ClassAverage

        End Function

After doing this function I then tried to write the answer to file:

FileOpen(2, strFilename, OpenMode.Append)
            Write(Grades + vbCrLf + vbCrLf)
            FileClose()

I then received a message that I did not declare grades. Please help.

In my ignorance, i tried writing Class Average to file but I received the same errors, Class Average is not declared

Try passing the array into the function:

Public Function ClassAverage(ByVal FinalGrades() As Decimal) As Decimal
    Dim sum As Decimal = 0
    For intCounter As Integer = 0 To FinalGrades.Length - 1
        sum += FinalGrades(intCounter)
    Next
    'When you use the function name as a variable it is automatically returned when the function ends.
    ClassAverage = (sum / FinalGrades.Length)
End Function

Then you would use it something like this:

Dim ClassGrades() As Decimal = {76.5D, 63.4D, 45.4D, 94.5D, 81.3D, 66.2D, 68.6D}
'Because ClassAverage is a function we can call the ToString method inherent to the return type, in this case Decimal
Dim Grades As String = ClassAverage(ClassGrades).ToString()
Dim sw As New IO.StreamWriter("test.txt", True)
sw.WriteLine(Grades + vbCrLf)
sw.Close()

thanks a lot, appreciated, errors are gone!

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.