|
|
|
|
int array[6]; // an array with 6 elements
std::vector<int> array;
for
loop. It seems to me that it would be more appropriate for your application than a while
loop.so on the next loop when it comes to serie it can take the new value of serie + the old value |
serie = serie + serieOld - serieOlder + serieOldest
tot_serie+=serie;//would this give you what you are looking for?
If you want to store multiple values, I suggest an array of some kind. if you know the size beforehand, create your array on the stack: int array[6]; // an array with 6 elements If you don't know the size, use something dynamic, such as std::vector: std::vector<int> array; Further reading Arrays: http://cplusplus.com/doc/tutorial/arrays/ Vectors: http://cplusplus.com/reference/stl/vector/ PS: You may wish to consider a for loop. It seems to me that it would be more appropriate for your application than a while loop. -Xander |
|
|
This: so on the next loop when it comes to serie it can take the new value of serie + the old value ....doesn't seem to equate with this: serie = serie + serieOld - serieOlder + serieOldest if under 'serie'....you inserted tot_serie+=serie;//would this give you what you are looking for |
|
|
|
|
|
|
|
|
Yes you can use arrays - that was my first suggestion. Don't increment the original array pointer, since each time you do, you're effectively "losing track" of an array element. But you can do this: 1 2 3 4 5 6 7 8 9 10 11 12 int array[10]; int iterator = 0; while (/* blah */) { // blah // get array element int temp = array[iterator]; // do something with array variables... // // move on to next array entry for next loop iteration ++iterator; } There are several different ways of working with arrays - you can use pointer notation as you did above, but not quite as you represented it. Personally, I think the method I demonstrated here is less confusing. In case you'd like to see the pointer way of doing it: |
int array[10];
|
|
i didn't think of using a integer instead of a number for the arrays size =) |
int array[a number