Question on milk or coffee for breakfast

Hi, I am making a GPA calculator, I am having problem with the loops I created, they always return the last value and which makes the GPA to 0. Can anyone tell me how to fix this? Here is my code

You did not add an aia export, so I have to give you the fix the hard way:

You were supposed to stop looping over the threshholds when you reached the highest one.
Hence the break.

Also, you were resetting the global gpOut variable each time, instead of having it accumulate over all the courses, hence the + operation.

By the way,

You did not need those global variables 1-6.
You could have fed the .Text values directly into the procedure.

Also, learn how to code value procedures, so you don't have to use global variables to return result.

Thank you for your advice, here is my aia file and I am still having questions on how to stop the loop when reach the highest one, can you show me how to do it? Than you very much

GPA Calc.aia (11.0 KB)

I have just change my code as you said in the picture, now the gpa is not 0 but it just keep adding everytime I click calculate.

Here are some suggested changes, using draggable blocks:

old:

new:


(Cleared global gpOut, the result of the procedure you will ne calling 6 times.)

new:


Note the addition, and the break.

Since the comparison goes down the grades from high to low, it will stop and break at the first grade that the pct exceeds.
I am probably missing adding the other number to the threshhold, based on level.

Here's your gradepoint procedure, changed to a value procedure:

You can make three variants of this, for AP, S, ...

Decide which variant to use based on level.

All blocks are draggable.

Thank you so much. I finally fix the loop problem.