Jump to content
Sign in to follow this  
ragnarok775

GPA Calculator

Recommended Posts

ragnarok775

This is one of my first submissions, I'm a beginner so bare with my code =P

This is a simple GPA calculator where you can calculate your GPA for up to 7 classes.

You input the amount of credits the class is worth on the left and the Grade on the right, You can put the grade in GPA Number format (4.00, 3.00, etc.) or Letter Grade, (A, B+, B, B-, C+, C, C- etc.)

GPACalc.exe

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=icon.ico
#AutoIt3Wrapper_Compression=4
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
$button_calc_y = 0
$GUI_height = 0
$GPA = 0
$NumClass = 0
$var = 0
$numcheck = 0
Func ask()
    $NumClass = InputBox("GPA Calculator", "How many classes are you taking? (2-7)", "", "", 220, 120)
    If @error = 1 Then
        Exit
    EndIf
    Call("Check")
    $button_calc_y = (($NumClass - 2) * 25) + 85
    $GUI_height = $button_calc_y + 70
EndFunc
Call("ask")

#include <GUIConstants.au3>

Func Check()
    If $NumClass > 7 Then
        MsgBox(0,"GPA - Error", "Invalid Amount of Classes, must be between 2 and 7")
        Call("ask")
    EndIf
    If $NumClass < 2 Then
        MsgBox(0,"GPA - Error", "Invalid Amount of Classes, must be between 2 and 7")
        Call("ask")
    EndIf
EndFunc

GUICreate("GPA", 240, $GUI_height)
GUISetState (@SW_SHOW)
;-----------------------------------------------------------

GuiCtrlCreateLabel("Credits",55,10)
GuiCtrlCreateLabel("Grade",110,10)
GuiCtrlCreateLabel("Grading Scale",165,$GUI_height/8)
GuiCtrlCreateLabel("A = 4.00",170,($GUI_height/8) + 15)
GuiCtrlCreateLabel("B = 3.00",170,($GUI_height/8) + 30)
GuiCtrlCreateLabel("C = 2.00",170,($GUI_height/8) + 45)
GuiCtrlCreateLabel("D = 1.00",170,($GUI_height/8) + 60)
GuiCtrlCreateLabel("F = 0.00",170,($GUI_height/8) + 75)
GuiCtrlCreateLabel("* Note: Under Grade you can type in a Number",7,($GUI_height - 35))
GuiCtrlCreateLabel("value or Letter Grade, examples: 4.0, B, C+",27,($GUI_height - 20))

$Button_calc = GUICtrlCreateButton ("Calculate",72, $button_calc_y, 60, 20)
    
If $NumClass > 1 Then
    $c1c = GUICtrlCreateInput ("",55, 30,45,20)
    $c1g = GUICtrlCreateInput ("",110, 30,45,20)
    GuiCtrlCreateLabel("Class 1",10,30)

    $c2c = GUICtrlCreateInput ("",55, 55,45,20)
    $c2g = GUICtrlCreateInput ("",110, 55,45,20)
    GuiCtrlCreateLabel("Class 2",10,55)
EndIf

If $NumClass > 2 Then
    $c3c = GUICtrlCreateInput ("",55, 80,45,20)
    $c3g = GUICtrlCreateInput ("",110, 80,45,20)
    GuiCtrlCreateLabel("Class 3",10,80)
EndIf

If $NumClass > 3 Then
    $c4c = GUICtrlCreateInput ("",55, 105,45,20)
    $c4g = GUICtrlCreateInput ("",110, 105,45,20)
    GuiCtrlCreateLabel("Class 4",10,105)
EndIf

If $NumClass > 4 Then
    $c5c = GUICtrlCreateInput ("",55, 130,45,20)
    $c5g = GUICtrlCreateInput ("",110, 130,45,20)
    GuiCtrlCreateLabel("Class 5",10,130)
EndIf

If $NumClass > 5 Then
    $c6c = GUICtrlCreateInput ("",55, 155,45,20)
    $c6g = GUICtrlCreateInput ("",110, 155,45,20)
    GuiCtrlCreateLabel("Class 6",10,155)
EndIf

If $NumClass > 6 Then
    $c7c = GUICtrlCreateInput ("",55, 180,45,20)
    $c7g = GUICtrlCreateInput ("",110, 180,45,20)
    GuiCtrlCreateLabel("Class 7",10,180)
EndIf

Func Calculate()
    If $NumClass > 1 Then
        $c1cF = GUICtrlRead($c1c)
        $c1gF = GUICtrlRead($c1g)
        $var = $c1gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c1gF = $var
        EndIf
        $c2cF = GUICtrlRead($c2c)
        $c2gF = GUICtrlRead($c2g)
        $var = $c2gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c2gF = $var
        EndIf
        $cct = $c1cF + $c2cF
        $cgt = ($c1cF * $c1gF) + ($c2cF * $c2gF)
    EndIf
    If $NumClass > 2 Then
        $c3cF = GUICtrlRead($c3c)
        $c3gF = GUICtrlRead($c3g)
        $var = $c3gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c3gF = $var
        EndIf
        $cct = $cct + $c3cF
        $cgt = $cgt + ($c3cF * $c3gF)
    EndIf
    If $NumClass > 3 Then
        $c4cF = GUICtrlRead($c4c)
        $c4gF = GUICtrlRead($c4g)
        $var = $c4gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c4gF = $var
        EndIf
        $cct = $cct + $c4cF
        $cgt = $cgt + ($c4cF * $c4gF)
    EndIf
    If $NumClass > 4 Then
        $c5cF = GUICtrlRead($c5c)
        $c5gF = GUICtrlRead($c5g)
        $var = $c5gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c5gF = $var
        EndIf
        $cct = $cct + $c5cF
        $cgt = $cgt + ($c5cF * $c5gF)
    EndIf
    If $NumClass > 5 Then
        $c6cF = GUICtrlRead($c6c)
        $c6gF = GUICtrlRead($c6g)
        $var = $c6gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c6gF = $var
        EndIf
        $cct = $cct + $c6cF
        $cgt = $cgt + ($c6cF * $c6gF)
    EndIf
    If $NumClass > 6 Then
        $c7cF = GUICtrlRead($c7c)
        $c7gF = GUICtrlRead($c7g)
        $var = $c7gF
        Call("LetterCheck")
        If $numcheck = 0 Then
            $c7gF = $var
        EndIf
        $cct = $cct + $c7cF
        $cgt = $cgt + ($c7cF * $c7gF)
    EndIf

    $GPA = $cgt/$cct
    $RGPA = Round($GPA, 3)

    MsgBox(0, "GPA Calculator", "Your GPA is: " & $RGPA)
EndFunc

Func LetterCheck()
    $numcheck = IsNumber($var)
    If $numcheck = 1 Then
    Else
        Select
            Case $var = "A"
                $var = 4
            Case $var = "A-"
                $var = 3.75
            Case $var = "B+"
                $var = 3.25
            Case $var = "B"
                $var = 3
            Case $var = "B-"
                $var = 2.75
            Case $var = "C+"
                $var = 2.25
            Case $var = "C"
                $var = 2
            Case $var = "C-"
                $var = 1.75
            Case $var = "D+"
                $var = 1.25
            Case $var = "D"
                $var = 1
            Case $var = "D-"
                $var = .75
            Case $var = "F"
                $var = 0
        EndSelect
    EndIf
EndFunc
;-----------------------------------------------------------
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_calc
            Call("Calculate")
    EndSelect
Wend

Share this post


Link to post
Share on other sites
gseller

Pretty Nifty!! :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×