"Dane Ensign" wrote:
> In the function I need to use a for loop to increment through my six
> dice variables that I set as global variables as:
> die1, ..., die6. I cant figure out how to append the value of my
> for-loop variable to the name of my "die" variable, so I can set it?
> Is there a better way to do this? Im not supposed to use an array for
> this assignment, but I am supposed to use a loop.
Hi Dane,
I din't get your original post, but if understand the above correctly, your
exercise looks much like an exercise I once had to explain to some students.
As to your question regarding "appending" (and to some rather misleading
replies you got to it): yes, you can append the "for value" to a variable
name, but the result would be a string, and not a variable name you could
use to access variable values.
I would say that the solution your teachers want to see would use either a
"switch" statement or, if you havn't learned switchs yet, six "if"
statements. Either way its not very pretty, but then again its supposed to
teach you something, not to be pretty ;)
Another hint: if you have to iterate more then 6 times in your for-loop you
might want to consider using the modulo operator "%".
Hope that helped a bit
Lior
dev...@li...
|