Iteration inside Procedure for AP CSP Portfoilio due 11:59 PM!


I needed an iteration within my procedure; Therefore, I made a for each item in list, it'll get my global calorie, and added a if then statement within that loop for lists. In sentence form, the first statement says if the calculation of calories is a larger value than any number in between 2300-2500, it'll say the text of overweight, and give advice. The second one is that if its less than the range of 2300-2500, it'll say underweight, and last one is that if global calorie or what's calculated after the user inserts the specification of height, weight, and age, it'll see if the global calorie is in between a range from 23000-2500, and it'll report this information on label 4. However, it just states an error: "The second argument to foreach is not a list. The second argument is: 0" within you Is it because I'm using random integers of a range between 2300-2500 or is it another issue.
Thank you for your time,
An AP CSP Student.

How does the list calorie look like?
According to your blocks the solution will be determined by the last item in the list
Also it does noit make much sense to have your variables overweight, average and underweight as lists, because each has only one item

Taifun
PS: every other hour somewhere in the world is midnight, so your information due at midnight does not really help...

11:59 EST. 3 hrs.

The random integer block returns a random value between 23000 and 25000, it is not a range

You probably mean

If calorie > 25000 then overweight
Else if calorie > 23000 then average
Else underweight

Again, what is the value of your global variable calorie... this is your second argument... and a list is expected... use Do it to debug your blocks

Taifun

1 Like

@Hyper
the value of your global variable calorie

based on a previous post, calorie is a variable so it is not a list. :cry:

you might consider some code like this if appropriate

caloriestatus

along with Taifun's suggestions