无法获取此用户输入值以供参考 [英] Cant get this user input value to reference

查看:115
本文介绍了无法获取此用户输入值以供参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在做这个家庭作业计划,但是我遇到了问题。我似乎无法在任何或函数或子中引用用户输入得分。我之前从未遇到过这个问题,所以我不确定我搞砸了哪里;我一直在努力想办法弄清楚哪里没有成功。如果有人可以提供帮助我会非常感激。



我尝试过的事情:



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:

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

推荐答案

我不是100%应用程序应该如何工作,但我相信你会在每个用户输入时覆盖得分变量。



代码有点倒退。



开头放

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


$循环中的
并且在得到分数后累积测试分数总和。



看起来CalcAvereage在错误的地方被调用。在你总共进行所有测试和测试次数之前,你无法计算平均值。



所以在所有测试分数之后你会想要它们在for循环之后输入....



你的逻辑还有其他问题,但这应该会让你更接近。祝好运。 : - )


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. :-)


您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

[ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
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[^]


这篇关于无法获取此用户输入值以供参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆