# Display Grade based on Points

Page 1 of 1

## 6 Replies - 12118 Views - Last Post: 15 November 2011 - 07:32 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=159159&amp;s=5b08b80dc7db854d844c66dca7d69dcb&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Perplexedwon

Reputation: 0
• Posts: 17
• Joined: 01-March 10

# Display Grade based on Points

Posted 01 March 2010 - 04:16 PM

I have a homework assignment to code an application that allows the Prof to display a grade based on the numnber of points he enter. The grading scale is : 0-299 -F; 300-349- D; 350-399- C; 400-449- B; 450-500- A. We are to store the minimum points in a 5 element one dimensional Integer array name intPonts and store the grades in a 5 element one dimensional String array name strGrades. The arrays should be parallel arrays. The procedure should search the intPoints array for the number of points entered by the user and then display the corresponding grade from the strGrades array.

I have stored the minimum points and grades in a one dimensional integer and string array respectively. I have coded the program, and when I put in random points, it gives me the letter grade. For example, if I put in 376 it will display a "C"; if I put in 200, it will display an "F". However, if I put in anything over 449, it will NOT display an "A", it just leaves the lbl blank. I am stumped on how to get the code to read pass 449 points.

here is my code:
```' Name:         Carver Project
' Purpose:      Displays a grade based on the number of points the user enters
' Programmer:   <Paul J. Williams> on <February 27, 2010>

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub txtPoints_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.Enter
txtPoints.SelectAll()
End Sub

Private Sub txtPoints_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPoints.KeyPress
' accepts only numbers and the Backspace key

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub

Private Sub txtPoints_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.TextChanged
End Sub

Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' Display the letter grade associated with a students total points earned.

Dim searchForPoints As Integer
Dim intPoints() As Integer = {450, 400, 350, 300, 0}
Dim strGrades() As String = {"A", "B", "C", "D", "F"}

' Assign a letter grade to a variable.

searchForPoints = Integer.Parse(Me.txtPoints.Text)

' Search the array for the grades

If searchForPoints >= 0 Or searchForPoints <= 500 Then

'End If

For intGrade = 0 To 4

End If
End If

End Sub
End Class

```

Is This A Good Question/Topic? 0

## Replies To: Display Grade based on Points

### #2 Merddin

Reputation: 12
• Posts: 37
• Joined: 19-February 10

## Re: Display Grade based on Points

Posted 01 March 2010 - 09:57 PM

It is because of this line in your code:

```If searchForPoints < intPoints(intGrade) Then

```

Since 450 is not greater than 450, this if is never entered and no value is assigned to the text box. Now, based on your code, we already know that the user has a value between 500 and 450 (inclusive). This is the only case where this is false. So, add in an Else If that process the false case to place an A in the text box.

```For intGrade = 0 To 4
Else If 'insert condition and code here

End If

```

Hope that helps and good luck with the coding.

### #3 myork

Reputation: 41
• Posts: 129
• Joined: 04-March 09

## Re: Display Grade based on Points

Posted 01 March 2010 - 11:04 PM

Merddin, on 01 March 2010 - 07:57 PM, said:

It is because of this line in your code:

```If searchForPoints < intPoints(intGrade) Then

```

Since 450 is not greater than 450, this if is never entered and no value is assigned to the text box. Now, based on your code, we already know that the user has a value between 500 and 450 (inclusive). This is the only case where this is false. So, add in an Else If that process the false case to place an A in the text box.

```For intGrade = 0 To 4
Else If 'insert condition and code here

End If

```

Hope that helps and good luck with the coding.

The label should be set to 'A' before that loop starts. If the mark is not supposed to be an 'A' then the loop will replace it. Adding an else if in the loop means that lblGrade.Text will always be 'A' unless searchForPoints < intPoints(4) is true, because whether or not it gets set to 'A' in previous iterations, it comes down to the final loop.
```searchForPoints = 401

For intGrade = 0 To 4
searchForPoints < intPoints(0) == 401 < 450 == True

searchForPoints < intPoints(1) == 401 < 400 == False
lblGrade.Text = "A"  'Not what we want'

```

This post has been edited by myork: 01 March 2010 - 11:05 PM

### #4 xoptimizedrsx

Reputation: 0
• Posts: 14
• Joined: 03-October 11

## Re: Display Grade based on Points

Posted 15 November 2011 - 07:02 PM

How about just doing it like this?
If you add in two Else IF you can sync all numbers in the input box as well as go above the 450 count.

```' Name:         Carver Project
' Purpose:      Displays a grade based on the number of points the user enters
' Programmer:   <Michael Cobb> on <11-15-2011>

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub txtPoints_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.Enter
txtPoints.SelectAll()
End Sub

Private Sub txtPoints_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPoints.KeyPress
' accepts only numbers and the Backspace key

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub

Private Sub txtPoints_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.TextChanged
End Sub

Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' Display the letter grade associated with a students total points earned.

Dim searchForPoints As Integer
Dim intPoints() As Integer = {450, 400, 350, 300, 0}
Dim strGrades() As String = {"A", "B", "C", "D", "F"}

' Assign a letter grade to a variable.

searchForPoints = Integer.Parse(txtPoints.Text)

' Search the array for the grades

For intGrade = 0 To 4

End If
Next

End Sub
End Class

```

### #5 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: Display Grade based on Points

Posted 15 November 2011 - 07:08 PM

You could retrieve the values, then do this:
```If grade >=450 AndAlso =< 500 Then
ElseIf
'Conditions follow
End If

```

So basically what that does is just test the conditions, if the number is less than 500 and greater than 450.

### #6 xoptimizedrsx

Reputation: 0
• Posts: 14
• Joined: 03-October 11

## Re: Display Grade based on Points

Posted 15 November 2011 - 07:25 PM

xoptimizedrsx, on 15 November 2011 - 07:02 PM, said:

How about just doing it like this?
If you add in two Else IF you can sync all numbers in the input box as well as go above the 450 count.

```' Name:         Carver Project
' Purpose:      Displays a grade based on the number of points the user enters
' Programmer:   <Michael Cobb> on <11-15-2011>

Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub

Private Sub txtPoints_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.Enter
txtPoints.SelectAll()
End Sub

Private Sub txtPoints_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPoints.KeyPress
' accepts only numbers and the Backspace key

If (e.KeyChar < "0" OrElse e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub

Private Sub txtPoints_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPoints.TextChanged
End Sub

Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' Display the letter grade associated with a students total points earned.

Dim searchForPoints As Integer
Dim intPoints() As Integer = {450, 400, 350, 300, 0}
Dim strGrades() As String = {"A", "B", "C", "D", "F"}

' Assign a letter grade to a variable.

searchForPoints = Integer.Parse(txtPoints.Text)

' Search the array for the grades

For intGrade = 0 To 4

End If
Next

End Sub
End Class

```

correction... sorry
the lower section is as follows to get things correctly reading as parallels. you can possibly remove one of the Else if's and it will still function as written in my book.

This Book is terrible and out dated..IMO

```For intGrade = 0 To 4

ElseIf searchForPoints > 450 Then
End If
Next

```

### #7 xoptimizedrsx

Reputation: 0
• Posts: 14
• Joined: 03-October 11

## Re: Display Grade based on Points

Posted 15 November 2011 - 07:32 PM

jimmyBo, on 15 November 2011 - 07:08 PM, said:

You could retrieve the values, then do this:
```If grade >=450 AndAlso =< 500 Then
ElseIf
'Conditions follow
End If

```

So basically what that does is just test the conditions, if the number is less than 500 and greater than 450.

That would work also But the book and Professor will want the lblgrade.text= strpoint(????)

They the Teachers) are so picky sometimes...

as for my personal project I still cant figure out my darn COM port use selected... I know its doable, but I'm to new programming and get lost on that area.