GPA Averages

The instruction is to allow user to check if male or female and then f

Page 1 of 1

10 Replies - 5631 Views - Last Post: 08 November 2008 - 05:09 PM Rate Topic: -----

#1 lawalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 08

GPA Averages

Post icon  Posted 01 April 2008 - 11:20 AM

I am not too far on my code. I attached my gui and would be helpful to know that I set it up correctly and that I am on the right track.

I don't know what strategy to use to allow user to input several different GPA's under male and female and then figure the averages. Any help would be greatly appreciated.
Thanks


Public Class mainform

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcombinationLabel.Click

    End Sub


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

    Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click
        Dim gpa As Decimal
        Dim InpGpa As String
        Const prompt As String = "Please enter GPA."
        Dim prompt2 As String = "Would you like to enter another GPA?"
        Dim isGPAok As Boolean

        Do While InpGpa <> "Done"
            InpGpa = InputBox("Type a name or Done to quit.")
            If InpGpa <> "Done" Then Print(InpGpa)
        Loop

    End Sub

    Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.xgenderListbox.Items.Add("Male")
        Me.xgenderListbox.Items.Add("Female")
        Me.xgenderListbox.SelectedIndex = 0





    End Sub


    
    Private Sub xgenderListbox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xgenderListbox.SelectedIndexChanged

    End Sub

    Private Sub xaverageGPAGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xaverageGPAGroupBox.Enter

    End Sub
End Class


This post has been edited by Master Pimp P. Flow: 01 April 2008 - 02:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: GPA Averages

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: GPA Averages

Posted 01 April 2008 - 02:53 PM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#3 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: GPA Averages

Posted 02 April 2008 - 01:25 PM

If it were me, I'd likely have a textbox that holds the values with a Listbox that could then have values added to it from the text box....along with a clear and calculate button. Then have the calculate button loop through the items in the listbox, adding them and then calculating the average....something like this

Public Class Form2

	Private Sub xbuttonAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbuttonAdd.Click

		lbGPA.Items.Add(txtGPA.Text)
		txtGPA.Text = ""
		txtGPA.Focus()

	End Sub

	Private Sub txtGPA_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtGPA.KeyPress

		If Asc(e.KeyChar) = Keys.Enter Then

			lbGPA.Items.Add(txtGPA.Text)
			txtGPA.Text = ""
			txtGPA.Focus()
			e.Handled = True

		End If

	End Sub

	Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click

		Dim count As Integer = lbGPA.Items.Count()
		Dim gpaTotal As Decimal = 0
		Dim gpaAvg As Decimal = 0

		For i As Integer = 0 To (count - 1)

			Dim current As Integer = i
			'Dim currVal As Decimal = lbGPA.Items.Item(current)

			gpaTotal += CType(lbGPA.Items.Item(current), Decimal)

		Next

		gpaAvg = gpaTotal / count

		lblResult.Text = "The average GPA is: " & Decimal.Round(gpaAvg, 2)

	End Sub

	Private Sub xbuttonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xbuttonClear.Click

		lbGPA.Items.Clear()

	End Sub

	Private Sub lbGPA_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbGPA.DoubleClick

		lbGPA.Items.Remove(lbGPA.SelectedItem)

	End Sub
End Class



At the end of the click event you can change the Decimal.Round number to whatever number you want for the number of decimal places. Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#4 lawalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 08

Re: GPA Averages

Posted 02 April 2008 - 08:15 PM

Ok, thank you for your reply no fear but i got it a little late. I am almost done but I still have a glich. Again the purpose is to allow the user to select a gender then a gpa and the program is to keep track of the average female gpa's, male gpa's and also combined gpa's. The problem is, my code returns 0 in all three of my labels. Any clue what i am doing wrong???? Thank You so much to whomever takes the time to reply.


'Angela  on April 1, 2008
'Purpose: Calculate Average GPA's
Option Strict On
Option Explicit On

Public Class mainform
   Private Sub xexitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xexitButton.Click
        Me.Close()
    End Sub

    Private Sub xcalculateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xcalculateButton.Click

        Dim i As Integer 'counter
        Dim imale As Integer 'male counter
        Dim ifemale As Integer 'female counter
        Dim accumulator As Decimal
        Dim accumulatorM As Decimal
        Dim accumulatorF As Decimal
        Dim combinedAvg As Decimal
        Dim maleavg As Decimal
        Dim femaleavg As Decimal
        
        maleavg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
        femaleavg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
        combinedAvg = Convert.ToDecimal(Me.xgenderListbox.SelectedIndex)
        Decimal.TryParse(Me.xcombinedResultsLabel.Text, combinedAvg)
        Decimal.TryParse(Me.xmaleavgResultsLabel.Text, maleavg)
        Decimal.TryParse(Me.xfemaleResultsLabel.Text, femaleavg)
       
        'average female gpa
        If Me.xgenderListbox.SelectedIndex = 0 Then
            i = i + 1
            ifemale = ifemale + 1
            accumulatorF = accumulatorF + femaleavg
            accumulator = accumulator + combinedAvg
            femaleavg = accumulatorF / ifemale
            combinedAvg = accumulator / i
            Me.xfemaleResultsLabel.Text = femaleavg.ToString
            Me.xcombinedResultsLabel.Text = combinedAvg.ToString

        Else
            i = i + 1
            imale = imale + 1
            accumulatorM = accumulatorM + maleavg
            accumulator = accumulator + combinedAvg
            maleavg = accumulatorM / imale
            combinedAvg = accumulator / i
            Me.xmaleavgResultsLabel.Text = maleavg.ToString
            Me.xcombinedResultsLabel.Text = combinedAvg.ToString
        End If

    End Sub

    Private Sub mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.xgenderListbox.Items.Add("Male")
        Me.xgenderListbox.Items.Add("Female")
        Me.xgenderListbox.SelectedIndex = 0

        For gpalistbox As Decimal = 2D To 4D Step 0.25D
            Me.xGpaListBox.Items.Add(gpalistbox.ToString)
        Next gpalistbox
        Me.xGpaListBox.SelectedIndex = 0

    End Sub

End Class



EDIT: Please use code tags => :code:

This post has been edited by PsychoCoder: 02 April 2008 - 09:05 PM

Was This Post Helpful? 0
  • +
  • -

#5 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: GPA Averages

Posted 03 April 2008 - 08:59 AM

Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?
Was This Post Helpful? 0
  • +
  • -

#6 lawalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 08

Re: GPA Averages

Posted 03 April 2008 - 09:58 AM

View Postnofear217, on 3 Apr, 2008 - 08:59 AM, said:

Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?



could you tell me how to send you a screen shot?
Was This Post Helpful? 0
  • +
  • -

#7 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: GPA Averages

Posted 03 April 2008 - 11:39 AM

You should just be able to copy (Alt+PrtScr) and then paste it into a post.
Was This Post Helpful? 0
  • +
  • -

#8 lawalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 08

Re: GPA Averages

Posted 03 April 2008 - 11:50 AM

View Postlawalker, on 3 Apr, 2008 - 09:58 AM, said:

View Postnofear217, on 3 Apr, 2008 - 08:59 AM, said:

Could you post a screenshot of what your form looks like so I can see from where the inputs of data are coming?



could you tell me how to send you a screen shot?


I will try to explain it to you in the mean time, the more i work on this the worse it gets.
I have a gender list box with male and female options. I also have a gpa list box with gpa's to choose from. In addition, I have a group box that will display my gpa results. One for Male one for female and one for the combination. The only two other buttons i have is a calculate and an exit button. I am also trying to post the GUI as this is due tomorrow and I don't have much time left to figure this out. Thanks for any help.
Was This Post Helpful? 0
  • +
  • -

#9 nofear217  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: GPA Averages

Posted 03 April 2008 - 01:26 PM

I guess what I'm trying to figure out is how you are separating the male and female gpas individually if you have a listbox with male/female (only 2) values and then another listbox with all the gpas of the males and females. That's why I was wanting to look at a screenshot so I could get a better idea of what we were working with. And I apologize, it looks like the copy and paste won't work in these forums. If you have windows/msn messenger you can contact me via jeremysydnor@hotmail.com and I'll see if we can't talk this through better in that manner rather than a forum.
Was This Post Helpful? 0
  • +
  • -

#10 lawalker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-February 08

Re: GPA Averages

Posted 03 April 2008 - 02:02 PM

View Postnofear217, on 3 Apr, 2008 - 01:26 PM, said:

I guess what I'm trying to figure out is how you are separating the male and female gpas individually if you have a listbox with male/female (only 2) values and then another listbox with all the gpas of the males and females. That's why I was wanting to look at a screenshot so I could get a better idea of what we were working with. And I apologize, it looks like the copy and paste won't work in these forums. If you have windows/msn messenger you can contact me via jeremysydnor@hotmail.com and I'll see if we can't talk this through better in that manner rather than a forum.




That's exactly what I have, 2 list boxes per my instructors wishes. I will have access to MSN a little later and will try to show u my interface then. Thank you for your time.
(I have been working on this all day and now my code is totally wacked, looks worse than before)
Was This Post Helpful? 0
  • +
  • -

#11 RookieDDZ  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-November 08

Re: GPA Averages

Posted 08 November 2008 - 05:09 PM

I'm coming across the same issue. What was this answer? My code is close to the same after I trashed mine. I saw hers was a better setup. Any news?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1