在我计算成绩的计划中,我需要找到最终获得某个成绩所需的百分比。
我计算变量PNA
,这是A所需的点数。
我做900 - GSF
(到目前为止等级)
为了获得满分,我需要回到50分。
然后,我执行变量PeNA
,这是最终结果所需的百分比。
所以我做了很多事情:
PeNA = PNA / 150
和
PeNA = (900-GSF) / 150
两个结果均产生0.00%
我知道结果应该是33.33%,但无济于事。
我的问题是如何格式化PeNA变量和Statement以返回正确的百分比。
我想我可能在某处遇到逻辑错误。但我不确定是什么问题。 一旦我弄明白,项目应该完成。
这是我的代码。
Sub Main()
Dim TG1 As Integer = -1
While TG1 < 0 Or TG1 > 200
Console.WriteLine("Please enter your grade for project #1 <0-200>: ")
TG1 = Console.ReadLine()
End While
Dim TG2 As Integer = -1
While TG2 < 0 Or TG2 > 200
Console.WriteLine("Please enter your grade for project #2 <0-200>: ")
TG2 = Console.ReadLine()
End While
Dim TG3 As Integer = -1
While TG3 < 0 Or TG3 > 200
Console.WriteLine("Please enter your grade for project #3 <0-200>: ")
TG3 = Console.ReadLine()
End While
Dim MT1 As Integer = -1
While MT1 < 0 Or MT1 > 150
Console.WriteLine("Please enter your grade on the midterm <0-150>: ")
MT1 = Console.ReadLine()
End While
Dim AB1 As Integer = -1
While AB1 < 0 Or AB1 > 30
Console.WriteLine("Please enter how much you were absent <0-30>: ")
AB1 = Console.ReadLine()
End While
Dim AB2 As Integer
If AB1 <= 2 Then AB2 = 100
If AB1 > 2 AndAlso AB1 < 8 Then AB2 = 100 - ((AB1 - 2) * 20)
If AB1 > 7 Then AB2 = 0
Dim GSF As Integer
GSF = TG1 + TG2 + TG3 + MT1 + AB2
Dim PNA As Integer
PNA = 900 - GSF
Dim PeNA As Integer
PeNA = (900 - GSF) / 150
Console.WriteLine("------------------------------------------------")
Console.WriteLine("--GRADE SUMMARY--")
Console.WriteLine("Project #1 : {0}", TG1)
Console.WriteLine("Project #2 : {0}", TG2)
Console.WriteLine("Project #3 : {0}", TG3)
Console.WriteLine("Midterm Exam : {0}", MT1)
Console.WriteLine("Participation : {0}", AB2)
Console.WriteLine("-------------------------------------------------")
Console.WriteLine("Total grade so far: {0}", GSF)
Console.WriteLine("")
Console.WriteLine("{0} {1} {2}", "Desired grade".PadRight(20), "Points needed".PadRight(20), "Percentage needed on final")
Console.WriteLine("{0} {1} {2}", "A".PadRight(20), PNA.ToString.PadRight(20), FormatPercent(PeNA).ToString.PadRight(20))
'A - 900-1000
'B - 800-899
'C - 700-799
'D - 600-699
答案 0 :(得分:1)
Dim PNA As Integer
PNA = 900 - GSF
Dim PeNA As Integer
PeNA = (900 - GSF) / 150
如果你想要它存储一个分数,PeNA应该被声明为SINGLE,DOUBLE或DECIMAL