0

In my program to calculate grades, I need to find the percentage needed on the final to get a certain grade. I calculate my variable PNA which is points needed for an A. I do 900 - GSF (which is grade so far) for a perfect score, I come back with 50 points needed.

Then, I do my variable PeNA, which is percentage needed on the final.

So I did multiple things: PeNA = PNA / 150 and PeNA = (900-GSF) / 150

Both results yielded 0.00%

I know that the result should be 33.33% but to no avail.

My question is how to format that PeNA variable and Statement to come back with the correct percent needed.

I think I might have a logic error somewhere in here. But I am not sure as to what is wrong. Once I figure this out the project should be done.

Here is my code.

  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
4

1 回答 1

1
Dim PNA As Integer
PNA = 900 - GSF

Dim PeNA As Integer
PeNA = (900 - GSF) / 150

PeNA should be declared SINGLE, DOUBLE or DECIMAL if you want it to store a fraction

于 2013-10-08T21:42:39.550 回答