GPA Calculator

Recommended Posts

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.)

```#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
\$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

#include <GUIConstants.au3>

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

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

GuiCtrlCreateLabel("Credits",55,10)
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
\$var = \$c1gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c1gF = \$var
EndIf
\$var = \$c2gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c2gF = \$var
EndIf
\$cct = \$c1cF + \$c2cF
\$cgt = (\$c1cF * \$c1gF) + (\$c2cF * \$c2gF)
EndIf
If \$NumClass > 2 Then
\$var = \$c3gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c3gF = \$var
EndIf
\$cct = \$cct + \$c3cF
\$cgt = \$cgt + (\$c3cF * \$c3gF)
EndIf
If \$NumClass > 3 Then
\$var = \$c4gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c4gF = \$var
EndIf
\$cct = \$cct + \$c4cF
\$cgt = \$cgt + (\$c4cF * \$c4gF)
EndIf
If \$NumClass > 4 Then
\$var = \$c5gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c5gF = \$var
EndIf
\$cct = \$cct + \$c5cF
\$cgt = \$cgt + (\$c5cF * \$c5gF)
EndIf
If \$NumClass > 5 Then
\$var = \$c6gF
Call("LetterCheck")
If \$numcheck = 0 Then
\$c6gF = \$var
EndIf
\$cct = \$cct + \$c6cF
\$cgt = \$cgt + (\$c6cF * \$c6gF)
EndIf
If \$NumClass > 6 Then
\$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```

Pretty Nifty!!

Share on other sites

Ragnarok, you do not need to use the Call function as I and Jos have pointed out.

Share on other sites

Works good for me... It coincided with the 4.6 I got last semester.

Share on other sites

This works pretty good. However you could have tried to make a more attractive interface like this tool here and can also try adding extra features.

Edited by novajones001

Share on other sites

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share on other sites

novajones001,

Welcome to the AutoIt forums.

But did you realise that the post above yours dates from nearly 11 years ago and the OP has not been here for the past 8 years? Please do not necropost in future - especially when criticism is all you have to offer.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share on other sites

That's what I said:

"I'd love to change the world", by Ten Years After (a British group).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share on other sites

jchd,

Sorry - I did not recognise the track - I know them more for this one:

Was it really over 50 years ago?

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share on other sites

Your bones, veins & [remaining] neurons can tell, just as mine.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)