Click here to Skip to main content
16,004,678 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I've been working on this homework program, however I'm running into a problem. I can't seem to get it to reference the user input for score in any or the functions or subs. I've never had this issue before so I'm not really sure where I messed up; I've been moving things around trying to figure out where it broke with no success. If anyone can help I'd really appreciate it.

What I have tried:

VB
Module Module1

    Sub Main()

        Dim CalcAgain As String = "y"

        While CalcAgain = "Y" Or CalcAgain = "y"
            Dim score As Integer
            Dim Counter As Integer = 5
            Dim Average As Integer
            Dim Count As Integer = 5
            Dim LetterGrade = ""
            Dim Accumulator As Decimal = 0

            Chart()
            LetterGrade = DetermineGrade(Average, score, LetterGrade)
            Average = CalcAverage(Counter, Accumulator)
            Accumulator = Accumulator + score

            For Counter = 1 To Count
                Console.Write("Please enter a test score: ")
                score = Console.ReadLine()
                Console.WriteLine("Letter: " & LetterGrade)
                While score > 100 Or score < 1
                    Count = Count + 1
                    Console.WriteLine("Invalid entry Pease enter a Numeric test score")
                    Console.WriteLine("between 0 and 100. Please re-enter your score:")
                    score = Console.ReadLine()
                End While
            Next


            DisplyResults(CalcAgain, score, Average, LetterGrade)

            Console.WriteLine("Would you like to calculate again? (y/n)")
            CalcAgain = Console.ReadLine()
        End While
    End Sub


End Module
Module GradeChart
    Sub Chart()
        Console.WriteLine("Grading Chart")
        Console.Write("Score")
        Console.Write(vbTab & vbTab & "Grade")
        Console.Write(vbCrLf & "90 - 100")
        Console.Write(vbTab & "A")
        Console.Write(vbCrLf & "80 - 89" & vbTab)
        Console.Write(vbTab & "B")
        Console.Write(vbCrLf & "70 - 79" & vbTab)
        Console.Write(vbTab & "C")
        Console.Write(vbCrLf & "60 - 69" & vbTab)
        Console.Write(vbTab & "D")
        Console.Write(vbCrLf & "Below 60")
        Console.Write(vbTab & "F")
        Console.WriteLine("")
        Console.WriteLine("Press any Key to Begin...")
        Console.ReadKey()
    End Sub
End Module
Module getAverage
    Function CalcAverage(ByRef Counter As Integer, ByRef Accumulator As Decimal) As Integer
        Dim Average As Integer
        Average = Accumulator / Counter
        Return Average
    End Function
End Module
Module GradeConversion
    Function DetermineGrade(ByRef Average As Integer, ByRef Score As Integer, ByRef LetterGrade As String) As String
        If (Score <= 100) And (Score >= 90) Then
            LetterGrade = "A"
        ElseIf (Score <= 89) And (Score >= 80) Then
            LetterGrade = "B"
        ElseIf (Score <= 79) And (Score >= 70) Then
            LetterGrade = "C"
        ElseIf (Score <= 69) And (Score >= 60) Then
            LetterGrade = "D"
        ElseIf Score < 60 Then
            LetterGrade = "F"
        End If
        Return LetterGrade
    End Function
End Module
Module Results
    Sub DisplyResults(ByRef CalcAgain As String, ByVal Score As Integer, ByRef Average As Integer, ByRef LetterGrade As String)
        Score = Average
        Console.WriteLine("Your average is: ")
        Console.WriteLine()
        Console.Write("Score")
        Console.Write(vbTab & "Letter")
        Console.Write(vbCrLf & Average)
        Console.Write(vbTab & LetterGrade)
    End Sub
End Module
Posted
Updated 4-Mar-16 9:48am

I am not 100% how the app is supposed to work, but I believe you are overwriting the score variable with every user input.

The code is kind of backwards.

Start with putting
Accumulator = Accumulator + score

inside the for loop and after you get the score so it accumulates a total of the test scores.

It looks like CalcAvereage is being called in the wrong place. You can't calculate the average until you have a total of all the tests and the number of tests.

So you would want them after all of the test scores are entered .... after the for loop.

There are other issues with your logic, but that should get you a little bit closer. Good Luck. :-)
 
Share this answer
 
Comments
Member 12312671 4-Mar-16 15:54pm    
I know its still a mess right now I haven't had time to go through it and sort it out (I usually throw the concept together and then clean it up after), the problem I'm having isn't with the average its with score itself; that's what I've narrowed it down to. As of right now I'm just trying to get letter grade to change it always sees if as an F. If I move score it to other places it wont see it at all. Once I get past the issue with score I think I can figure it out from there.
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900