I just started learning C++ in college and my task is to do the following: I have to write some code that will use iteration (i.e. looping) to calculate the cumulative sum of the items in an array of integers; my code is:
int main() {
int myArray[] = {1,2,3,4,5};
int i;
int j;
j+= myArray[];
for(i=0;i<5;i++){
printf("%d\n",myArray[j]);
}
}
Although this code does not produce what I am looking for and I am confused as to what I should do next.
jbecome 15?for (int i = ... ). There is no reason why an accumulator variable should be calledj. Fix that bad habit and hordes of developers that have to maintain your code in the future will sing your praises rather than curse your mother for producing such vile issue :-)