Brian Barrick wrote:How long are you wanting to store these grades? If it's something you want stored indefinitely then I think you'd have to write them to a text file. With the exception of constants, if I'm not mistaken, data in a program only lasts while the program is running.
Junilu Lacar wrote:A nested for-loop won't help you here, nor is it appropriate for your problem. You either need an array to store multiple grades or you can just calculate the end result as you go. You can't, however, keep using just the grade variable. You will need another variable to keep track of the results you have calculated so far, like a running total. These kinds of variables are called "accumulators" because they are used to accumulate the results of multiple calculations, such as those that are done in a loop.
Example:
Here the variable sum is an accumulator -- it keeps track of the running total of all the numbers that have been processed so far in the loop. When the loop exits, sum will contain the result of adding all the numbers from 1 to 100, which should be equal to 5050.
Junilu Lacar wrote:If you're counting in a loop where the variable i takes the values from 0, 1, 2, ..., 9 and you want to access elements grade[0], grade[1], grade[2], ..., grade[9], how do you think you would do that? Can you see a pattern? You can use i in any way and any number of times inside the loop. And you can use other variables, too. There's practically no restrictions to what you can do inside a loop. Well, there are but the restrictions are kind of common sense things to keep you out of trouble.
Adam Chalkley wrote:
Junilu Lacar wrote:If you're counting in a loop where the variable i takes the values from 0, 1, 2, ..., 9 and you want to access elements grade[0], grade[1], grade[2], ..., grade[9], how do you think you would do that? Can you see a pattern? You can use i in any way and any number of times inside the loop. And you can use other variables, too. There's practically no restrictions to what you can do inside a loop. Well, there are but the restrictions are kind of common sense things to keep you out of trouble.
thanks for the reply =)
but I was also looking how to populate the array with a for loop I learned this 2 years ago in college but can't seem to remember it,I thought it would be pretty easy to find a tutorial online but there's actually nothing =(,the part I don't know is how to actually assign them.
Don't get me started about those stupid light bulbs. |