Put inputs into array

How do I make it to where the program takes 10 integers from user and puts them into this array? Thanks!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  #include<iostream>
using namespace std;

int main()
{
	// array variable declaration and initialization:
	const int SIZE = 10;
	int numbers[SIZE] = {};
	
	
	int highest;
	highest = numbers[0];
	for (int i = 0; i < SIZE ; i++)
	{
		cout<<"current number is: "<<numbers[i]<<"\t"
		<<"current highest number is: "<<highest<<endl;
		
		if (numbers[i] > highest)
			highest = numbers[i];
	}
	
	cout<<"The highest number in the array is: "<<highest<<endl;
	

	return 0;
}

'std::cin' is the stream that receives user input.

One possibility, add the following somewhere before line 11;

1
2
3
4
5
cout << "Enter " << SIZE << " numbers: ";
for (int i = 0; i < SIZE; i++)
{
    cin >> numbers[i];
}


The alternative is to ask for input interlaced between calculating the maximum so far, in which case you'd want to put the cin >> statement within your for loop (lines 13 - 20), and have another cin statement before line 12 (to enter numbers[0]).
Last edited on
Topic archived. No new replies allowed.