Need help finishing this GPA calculator!

• (2 Pages)
• 1
• 2

19 Replies - 2434 Views - Last Post: 20 July 2014 - 06:44 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=350420&amp;s=9f320c9e599da1ac3f8691c2aa244473&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 ranks0213

Reputation: 0
• 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.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

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

• Custom Control Freak

Reputation: 1475
• Posts: 3,734
• 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.

#3 ranks0213

Reputation: 0
• 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.

#4 IronRazer

• Custom Control Freak

Reputation: 1475
• Posts: 3,734
• 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

#5 ranks0213

Reputation: 0
• 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.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

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

```

#6 ranks0213

Reputation: 0
• 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.

#7 Oppemaj

Reputation: 23
• Posts: 94
• 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?

#8 ranks0213

Reputation: 0
• 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

#9 IronRazer

• Custom Control Freak

Reputation: 1475
• Posts: 3,734
• 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

#10 Oppemaj

Reputation: 23
• Posts: 94
• 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

#11 IronRazer

• Custom Control Freak

Reputation: 1475
• Posts: 3,734
• 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 ?

#12 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12242
• Posts: 45,328
• 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.

#13 ranks0213

Reputation: 0
• 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.

#14 Oppemaj

Reputation: 23
• Posts: 94
• 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

#15 IronRazer

• Custom Control Freak

Reputation: 1475
• Posts: 3,734
• 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.