Need help finishing this GPA calculator!

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 787 Views - Last Post: 20 July 2014 - 06:44 PM Rate Topic: -----

#1 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Need help finishing this GPA calculator!

Posted 15 July 2014 - 03:34 PM

I cant get this to calculate correctly. Any advice would be greatly appreciated.

'GPA Calculator

Option Explicit On
Option Infer Off
Option Strict On


Public Class frmMain

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

    End Sub
    Private Sub gpaListBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

        'fills GPA Score
        gpaListBox.Items.Add("4.0")
        gpaListBox.Items.Add("3.9")
        gpaListBox.Items.Add("3.8")
        gpaListBox.Items.Add("3.7")
        gpaListBox.Items.Add("3.6")
        gpaListBox.Items.Add("3.5")
        gpaListBox.Items.Add("3.4")
        gpaListBox.Items.Add("3.3")
        gpaListBox.Items.Add("3.2")
        gpaListBox.Items.Add("3.1")
        gpaListBox.Items.Add("3.0")
        gpaListBox.Items.Add("2.9")
        gpaListBox.Items.Add("2.8")
        gpaListBox.Items.Add("2.7")
        gpaListBox.Items.Add("2.6")
        gpaListBox.Items.Add("2.5")
        gpaListBox.Items.Add("2.4")
        gpaListBox.Items.Add("2.3")
        gpaListBox.Items.Add("2.2")
        gpaListBox.Items.Add("2.1")
        gpaListBox.Items.Add("2.0")
        gpaListBox.Items.Add("1.9")
        gpaListBox.Items.Add("1.8")
        gpaListBox.Items.Add("1.7")
        gpaListBox.Items.Add("1.6")
        gpaListBox.Items.Add("1.5")
        gpaListBox.Items.Add("1.4")
        gpaListBox.Items.Add("1.3")
        gpaListBox.Items.Add("1.2")
        gpaListBox.Items.Add("1.1")
        gpaListBox.Items.Add("1.0")
        gpaListBox.Items.Add("0.9")
        gpaListBox.Items.Add("0.8")
        gpaListBox.Items.Add("0.7")
        gpaListBox.Items.Add("0.6")
        gpaListBox.Items.Add("0.5")
        gpaListBox.Items.Add("0.4")
        gpaListBox.Items.Add("0.3")
        gpaListBox.Items.Add("0.2")
        gpaListBox.Items.Add("0.1")

        gpaListBox.SelectedIndex = -1

    End Sub




    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click


        Static maleGPA As Double
        Static femaleGPA As Double
        Static malestudent As Integer
        Static femalestudent As Integer
        Static totalGPA As Double
        Dim totalmaleGPA As Double
        Dim totalfemaleGPA As Double
        


        'Accumalate gpa

        If radMale.Checked Then
            malestudent = +1
            maleGPA = CDbl(gpaListBox.SelectedItem.ToString) + maleGPA
            totalmaleGPA = maleGPA / malestudent
        Else
            femalestudent = +1
            femaleGPA = CDbl(gpaListBox.SelectedItem.ToString) + femaleGPA
            totalfemaleGPA = totalfemaleGPA / femalestudent

        End If


        'Declare variables

        If malestudent + femalestudent <= 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / 1
        ElseIf malestudent + femalestudent > 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / (malestudent + femalestudent)

        End If

        'Show results
        allLabel.Text = totalGPA.ToString("N2")
        femaleLabel.Text = totalfemaleGPA.ToString("N2")
        maleLabel.Text = totalmaleGPA.ToString("N2")


    End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Need help finishing this GPA calculator!

#2 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 215
  • View blog
  • Posts: 726
  • Joined: 01-February 13

Re: Need help finishing this GPA calculator!

Posted 15 July 2014 - 05:15 PM

Hi,
I believe what your trying to do is add 1 to the malestudent and femalestudent integers each time the calculate button is clicked depending on the RadioButton that is selected. To add 1 to them then you want to use += like this for both of them.
malestudent += 1


That should get you in the rite direction but, i think you will find you may need to change some of this code to compare and calculate the averages
        If malestudent + femalestudent <= 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / 1
        ElseIf malestudent + femalestudent > 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / (malestudent + femalestudent)
        End If



I can`t do this for you because it looks like homework so, you will have to figure out the calculations. B)
Was This Post Helpful? 1
  • +
  • -

#3 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Re: Need help finishing this GPA calculator!

Posted 15 July 2014 - 05:38 PM

Thanks! I will give it a shot when i get home.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 215
  • View blog
  • Posts: 726
  • Joined: 01-February 13

Re: Need help finishing this GPA calculator!

Posted 15 July 2014 - 06:00 PM

Your welcome. I am not sure if the second part where i said you may need to change the code is a problem. You will need to test the first part i suggested and then if it is not working the way you want you should set a break point on the line shown below and step through the code one line at a time so you can see the flow of the code and hover the mouse over the variables to see the values of them.
If radMale.Checked Then


There are a few Debugging tutorials here on DIC that you can check out if you don`t know how to do this.

Debugging Express

Debbuging How To Use The Tools

And here is a tutorial on CodeProject also.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide

This post has been edited by IronRazer: 15 July 2014 - 06:01 PM

Was This Post Helpful? 0
  • +
  • -

#5 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Re: Need help finishing this GPA calculator!

Posted 18 July 2014 - 06:55 PM

I still needs some help with the calculating. It works with the first student but gives the wrong calculation after the first student.

'GPA Calculator

Option Explicit On
Option Infer Off
Option Strict On


Public Class frmMain

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

    End Sub
    Private Sub gpaListBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

        'fills GPA Score
        gpaListBox.Items.Add("4.0")
        gpaListBox.Items.Add("3.9")
        gpaListBox.Items.Add("3.8")
        gpaListBox.Items.Add("3.7")
        gpaListBox.Items.Add("3.6")
        gpaListBox.Items.Add("3.5")
        gpaListBox.Items.Add("3.4")
        gpaListBox.Items.Add("3.3")
        gpaListBox.Items.Add("3.2")
        gpaListBox.Items.Add("3.1")
        gpaListBox.Items.Add("3.0")
        gpaListBox.Items.Add("2.9")
        gpaListBox.Items.Add("2.8")
        gpaListBox.Items.Add("2.7")
        gpaListBox.Items.Add("2.6")
        gpaListBox.Items.Add("2.5")
        gpaListBox.Items.Add("2.4")
        gpaListBox.Items.Add("2.3")
        gpaListBox.Items.Add("2.2")
        gpaListBox.Items.Add("2.1")
        gpaListBox.Items.Add("2.0")
        gpaListBox.Items.Add("1.9")
        gpaListBox.Items.Add("1.8")
        gpaListBox.Items.Add("1.7")
        gpaListBox.Items.Add("1.6")
        gpaListBox.Items.Add("1.5")
        gpaListBox.Items.Add("1.4")
        gpaListBox.Items.Add("1.3")
        gpaListBox.Items.Add("1.2")
        gpaListBox.Items.Add("1.1")
        gpaListBox.Items.Add("1.0")
        gpaListBox.Items.Add("0.9")
        gpaListBox.Items.Add("0.8")
        gpaListBox.Items.Add("0.7")
        gpaListBox.Items.Add("0.6")
        gpaListBox.Items.Add("0.5")
        gpaListBox.Items.Add("0.4")
        gpaListBox.Items.Add("0.3")
        gpaListBox.Items.Add("0.2")
        gpaListBox.Items.Add("0.1")

        gpaListBox.SelectedIndex = -1

    End Sub




    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click


        Static maleGPA As Double
        Static femaleGPA As Double
        Static malestudent As Integer
        Static femalestudent As Integer
        Static totalGPA As Double
        Dim totalmaleGPA As Double
        Dim totalfemaleGPA As Double
        


        'Accumalate gpa

        If radMale.Checked Then
            malestudent += 1
            totalmaleGPA = CDbl(gpaListBox.SelectedItem.ToString) + totalmaleGPA
            maleGPA = totalmaleGPA / malestudent
            totalGPA = (totalfemaleGPA + totalmaleGPA) / (malestudent + femalestudent)
        Else
            femalestudent += 1
            totalfemaleGPA = CDbl(gpaListBox.SelectedItem.ToString) + totalfemaleGPA
            femaleGPA = totalfemaleGPA / femalestudent

        End If


        'Declare variables

        If malestudent + femalestudent < 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / 1
        ElseIf malestudent + femalestudent >= 1 Then
            totalGPA = (totalmaleGPA + totalfemaleGPA) / (malestudent + femalestudent)

        End If

        'Show results
        allLabel.Text = totalGPA.ToString("N2")
        femaleLabel.Text = femaleGPA.ToString("N2")
        maleLabel.Text = maleGPA.ToString("N2")


    End Sub

End Class


Was This Post Helpful? 0
  • +
  • -

#6 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Re: Need help finishing this GPA calculator!

Posted 18 July 2014 - 07:21 PM

I think it has something to do with the counter.
Was This Post Helpful? 0
  • +
  • -

#7 Oppemaj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 73
  • Joined: 15-November 13

Re: Need help finishing this GPA calculator!

Posted 18 July 2014 - 07:39 PM

Let me make sure that I understand.
Suppose the threes first scores are selected for male: 4- 3.9- 3.8
Then the total is 11.7 and the average is 3.9
Is this correct?
Was This Post Helpful? 0
  • +
  • -

#8 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Re: Need help finishing this GPA calculator!

Posted 18 July 2014 - 07:44 PM

yes. I would need to show: Total GPA - 3.9
Male GPA - 3.9
Female GPA - 0.0
Was This Post Helpful? 0
  • +
  • -

#9 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 215
  • View blog
  • Posts: 726
  • Joined: 01-February 13

Re: Need help finishing this GPA calculator!

Posted 19 July 2014 - 04:19 AM

Hi,
You need to change some of your code around a little. You will need to move the calculations of the maleGPA and femaleGPA into there own If Then statements that check to see if the count of male or female students is greater than 0.

Then you will need to just calculate the totalGPA no mater how many male or female students there are. There will be at least 1 or more when the button gets pressed. Also, for the totalGPA you want to add the maleGPA and the femaleGPA together instead of the totalmaleGPA and totalfemaleGPA and then divide it by the count of both male and female students.

Here is what i mean. Please look it over good to see the flow of the code. If you write things down on paper and figure out what each variable is doing in your code you will see where your running into problems. That is why i suggested setting a break point and stepping through the code one line at a time and seeing how the code flowed and what the variables values where.

Learning to debug your code will save you a lot of headaches when you start getting into larger and more complicated codes.

        If radMale.Checked Then
            malestudent += 1 'Add 1 to the male student count
            maleGPA = CDbl(gpaListBox.SelectedItem.ToString) + maleGPA 'add the gpa to the males gpa
        Else
            femalestudent += 1 'Add 1 to the female student count
            femaleGPA = CDbl(gpaListBox.SelectedItem.ToString) + femaleGPA 'add the gpa to the females gpa
        End If

        If malestudent > 0 Then
            totalmaleGPA = maleGPA / malestudent 'if there is at least 1 male student then calculate the male total gpa
        End If
        If femalestudent > 0 Then
            totalfemaleGPA = femaleGPA / femalestudent 'if there is at least 1 female student then calculate the female total gpa
        End If

        totalGPA = (maleGPA + femaleGPA) / (malestudent + femalestudent) 'Calculate the gpa for all students



This post has been edited by IronRazer: 19 July 2014 - 04:21 AM

Was This Post Helpful? 1
  • +
  • -

#10 Oppemaj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 73
  • Joined: 15-November 13

Re: Need help finishing this GPA calculator!

Posted 19 July 2014 - 04:43 PM

I asked you that question yesterday and it was late in my region.

This is how your code should look like. I hope that you will study it and learn.

<Removed> 

This post has been edited by macosxnerd101: 20 July 2014 - 01:27 PM

Was This Post Helpful? 0
  • +
  • -

#11 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 215
  • View blog
  • Posts: 726
  • Joined: 01-February 13

Re: Need help finishing this GPA calculator!

Posted 20 July 2014 - 08:37 AM

Hi ranks0213,
Did you get it working ?
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10396
  • View blog
  • Posts: 38,464
  • Joined: 27-December 08

Re: Need help finishing this GPA calculator!

Posted 20 July 2014 - 01:27 PM

Oppemaj- Let's not hand folks completed homework assignments.
Was This Post Helpful? 0
  • +
  • -

#13 ranks0213  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-July 10

Re: Need help finishing this GPA calculator!

Posted 20 July 2014 - 02:01 PM

Thank you all for the help! Yea, IronRazer you totally got it. I was supposed to add malegpa and femalegpa, not totalmale and totalfemale. Also the labels were to display the totals. Thanks for the help guys. Im not very good at VB, Im a web design student but im required to take this course.
Was This Post Helpful? 0
  • +
  • -

#14 Oppemaj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 16
  • View blog
  • Posts: 73
  • Joined: 15-November 13

Re: Need help finishing this GPA calculator!

Posted 20 July 2014 - 02:05 PM

Yes, you're right. I won't do it again. And I'm really sorry.
Thank you for reminding me of that.
In fact, in my first appearance, it was astonnecipher who advised and I didn't listen to him.
Thank you both. I promise I won't do it again.

P.S: sorry, I don't know how to write userame the way I see it in other threads.

This post has been edited by Oppemaj: 20 July 2014 - 05:01 PM

Was This Post Helpful? 0
  • +
  • -

#15 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 215
  • View blog
  • Posts: 726
  • Joined: 01-February 13

Re: Need help finishing this GPA calculator!

Posted 20 July 2014 - 02:15 PM

Quote

Thank you all for the help! Yea, IronRazer you totally got it. I was supposed to add malegpa and femalegpa, not totalmale and totalfemale. Also the labels were to display the totals. Thanks for the help guys. Im not very good at VB, Im a web design student but im required to take this course.


Your Welcome. Glad it helped. :)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2