User input into int array

So I am doing a question in class and I can't seem to get the program to place the user input into the array and then display each of the results back to me at the end.

I want the user to input 10 numbers into the array and then once that is complete I want the program to display all the numbers that have been input for me. The question asks me to use a while loop to initialize the array

Here is what I have at the moment:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;


int ihighscores[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
int userinput = 0;


int main()
{
	for (int i = 0; i != 10; ++i)
	{
		cin >> userinput;

	}
	cout << ihighscores[userinput] << "\n";


	return 0;
}
Last edited on
So, based on what you asked, you basically have these problems:

1) a while loop initialize array
2) a way to ask for the numbers
3) where and how to put the numbers
4) a way to check if we already got 10 numbers
5) how to print the numbers

Which one are you having issues with?
Number 3, 4 and 5 sound like exactly what I am stuck on
3)

Well you already have your array, which is ihighscores[].

Although you shouldn't do int ihighscores[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9} since you're being asked to initialize it in a while loop ( you did it manually). And we need an array of size 10 for 10 inputs.
Which is int ihighscores[10]; <- That isn't filled with anything yet, so fire up the while loop and fill it up with 0's first. (this is initialization)

That's where you put the scores.

How? By using the array with each spot as one user input. Read this if you're confused how to access an array: http://www.cplusplus.com/doc/tutorial/arrays/

Basically ihighscores[0] is for the first input, ihighscores[1] is for the second... etc.
Last edited on
You are amazing and I want to kiss you.

Thank you!!!!
Topic archived. No new replies allowed.