View Full Version : Problem with variable assignments? Or just me?

09-23-2010, 10:30 AM
Here is an algorithm for a problem involving simple decisions and variable assignment that I am using with a grade 11 high school Computer Science class:

Algorithms Practice - Canadian Calorie Counting (http://mrgordon.info/alice3/Algorithms-Practice-Canadian-Calorie-Counting.pdf)

Here, using the current Alice 3 beta, is my partial implementation of this algorithm (does the "burger choice" only):

Canadian Calorie Counting Problem - Alice 3 Implementation (http://mrgordon.info/alice3/SimpleDecisionsAndVariables.a3p)

My problem is that the assignment statements for totalCalories inside the "if" control structures do not seem to be working.

Am I missing something obvious -- or is this a bug in the current beta of Alice 3? I am using on Mac OS X 10.6.4.

Please help / take a look if you can -- I know Alice 3 is being used at CMU -- I'd hoped to use it this semester with my CS classes.

Thanks in advance for anyone's time. All the best! Alice 3, in overall sense, is looking great!

09-24-2010, 02:03 PM
Key was that by dragging "local" variable tiles inside the "if" structures, I ended up with multiple instances of the totalCalories variable, with a scope that exists inside each "if" structure.

This can be avoided by (what I consider to be) the good programming practice of always initalizing your variables at the start of a method / procedure.

Here's a video that I gave to my class, showing them how to get started with this program (the right way, to avoid the problem I encountered):

Alice 3 Tutorial - User Input and Variables (http://northparkvikings.ca/classes/gordon-ics3u-f10/files/2010/09/Alice-3-Tutorial-User-Input-and-Variables.mov)