Array for loops

Solved thanks.
Last edited on
You just put it in the same for-loop, but it just does something differently.

Your array is of size 7. Your first loop runs 6 times. Which is a problem. Remember array indexes start from 0. So your array of size 7 goes from 0-6, so the for-loop should look like this -

1
2
3
4
for(int i = 0; i < 7; i++)
{
    //Do ya thang here
}


That will run from 0-6.

Then you will need an identical loop, to print out each content within the array, and also store each individual value in the array (scores[0], scores[1] etc) inside a variable double total;

And then outside the for loop at the end just print out the total.
Last edited on
Arrays start at index 0 & go to (x-1) so in this case 6. Your for loop starts at 1 and goes to 6, so you're losing one number.

As for putting in another for loop, you just add in a for loop. It will be practically the same loop as your first one, but with a different body.
Last edited on


My cout statement seems to be flawed..
Last edited on
I dont know what you mean by flawed, since it works perfectly fine for me. What seems to be the problem?

Also try implementing the second for-loop :)

Gives me the correct sum and everything.
Last edited on
IS this suppose to happen?
If you enter seven numbers separated by a space character instead of a end of line character (enter) your output is to be expected. Remember the insertion operator>> stops processing input when it encounters a whitespace character, leaving any unprocessed characters in the input buffer for the next input operation.

You're supposed to press enter after each number, so it maybe should be -

1
2
cout << "Enter number " << i + 1 << " of 7: ";
cin >> scores[i];

@jlb

I don't think my program is storing in these numbers into an array/printing them out..

:(


Is this program doing what is being asked?
Last edited on
Not exactly.

and then prints out each of them, followed by the total.


You never print out each of them. You can do that in the second for-loop.
@TarikNeaj

How exactly can I show the inputted numbers?

[/code]

How can I add spaces to the inputted numbers (after it printed the array?)
Last edited on
Solved.
Do you have to remove your initial post?, other people may find this useful in the future.
Topic archived. No new replies allowed.