6 Replies - 2398 Views - Last Post: 05 November 2011 - 09:52 PM Rate Topic: -----

#1 blackbyron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 08-September 11

Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 10:59 AM

Hello, I just learned basic arrays, I'm writing a program the allows Professor Carver to display a grade based on the number of possible points he enters in the inputbox (strMax). Then the user enters the points he earned in the textbox (dblPoints)

Then I solve the percentage. dblResults = dblPoints/CDbl(strMax)

The first step is to store the minimum percentage points in one dimensional array. I did that.

The second step is to store the grades in one dimensional array. I did that.

The arrays should be parallel arrays. <------ Having trouble with it

It then should display the corresponding grade from the strGrades array <---- Not done.

I'm having trouble to display arrays in that are parallel.

I tried this one http://www.dreaminco...ased-on-points/

but some of them, I find it complicated, I just want to make this easier to code.

Any ideas.


Option Explicit On
Option Strict On
Option Infer Off

Public Class frmMain
    ' declare class variable
    Private strMax As String

    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
        lblGrade.Text = String.Empty
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' get the total number of possible points
        strMax =
            InputBox("Enter the total possible points.", "Professor Carver")

    End Sub

    Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
        ' display the grade the student gets
        Dim dblPoints As Double
        Dim dblResults As Double
        Dim strGrade() As String =
            {"A", "B", "C", "D", "F"}
        Dim dblPer() As Double =
            {0.9, 0.8, 0.7, 0.6, 0.5}

        Double.TryParse(txtPoints.Text, dblPoints)
        ' displays the percentage the student recieves
        dblResults = dblPoints / CDbl(strMax)
        ' determines the grade
        For intGrade As Integer = 0 To strGrade.Length
            If dblResults <= dblPer(intGrade) Then

            End If

        Next intGrade
    End Sub
End Class



Thanks

This post has been edited by blackbyron: 05 November 2011 - 11:06 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Carver- Setting up Parallel Arrays

#2 blackbyron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 08-September 11

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 11:14 AM

Update:

I added

       For intGrade As Integer = 0 To strGrade.GetUpperBound(0)
            If dblResults <= dblPer(intGrade) Then
                lblGrade.Text = strGrade(intGrade)
            End If



But I'm still having trouble with parallel the arrays.

I think I'm getting close, any suggestions?

This post has been edited by blackbyron: 05 November 2011 - 11:15 AM

Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,450
  • Joined: 29-May 08

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 11:55 AM

What is it with so called "Professors" and their love affair with parallel arrays?
Why teach them stuff that is in my opinion decades out of date.
The programming language has moved on. We should not be have to resort to using them in an Object Oriented Language.

Teach them about classes, structures and algorithmic designs.

Tutorial: Parallel Arrays, Array with Object (Class & Structure)
Was This Post Helpful? 2
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 12:16 PM

Agreed Adam.
Was This Post Helpful? 0
  • +
  • -

#5 blackbyron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 08-September 11

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 08:26 PM

Well, the reason I need to program in parallel arrays is because the assignment requires me to do it. I know there's an easy way to do this, but I couldn't. I just look at the parallel arrays tutorial, but to me it's seems complicated. Is there an easier way to know basics of parallel arrays?

I find this one easier to do this.

If dblResults <= dblPer(0) Then
            lblGrade.Text = strGrade(0)
        ElseIf dblResults <= dblPer(1) Then
            lblGrade.Text = strGrade(1)


This post has been edited by blackbyron: 05 November 2011 - 08:35 PM

Was This Post Helpful? 0
  • +
  • -

#6 blackbyron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 08-September 11

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 08:52 PM

Sorry for the double post,

but I think I'm really close.

Here's the part of the code for the parallel array.


 For intGrade As Integer = 0 To strGrade.GetUpperBound(0)
            If dblResults <= dblPer(intGrade) Then
                lblGrade.Text = strGrade(intGrade)
            End If



I typed 100 as the possible points for the input box, but then when I type 90, 80, 70, 60, 50, it shows that grade, but not when I type 52, 70, because it shows, I know there's something wrong with the if statement, but I don't think I understand what is wrong with it. Any suggestions.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#7 blackbyron  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 08-September 11

Re: Carver- Setting up Parallel Arrays

Posted 05 November 2011 - 09:52 PM

Update:

I apologize for another post again. But I'm pretty close to get the program working, expect I'm getting the indexOutofRange error when I type 45, instead if showing "F" in the lblGrade.text. From the link above that I posted earlier, I don't understand he didsn't get the error, but I do get the error.

Any suggestions? Again, I'm sorry for the triple post. I just want to update what I have done.
  If dblResults >= dblPer(0) Then
                lblGrade.Text = strGrade(0)
            Else
                For intGrade As Integer = 0 To 4
                    If dblResults < dblPer(intGrade) Then
                        lblGrade.Text = strGrade(intGrade + 1)
                    End If
                Next intGrade
            End If



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1