Arrays

I am having trouble trying to figure out how to get user inputs into an array. I have to get 10 user inputs into the array and I'm trying to use a loop but once I run it it crashes whenever you input the first value. I've been stuck on this for hours now trying to do some research so any help is appreciated.

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
29
30
31
32
33
34
35
#include <stdio.h>
#define SIZE 10

void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);

size_t counter1 = 0;


int main( void )
{
int array1 [ SIZE ];
int average;


Input(array1);



}




void Input(const int array1[])
{
	while (counter1 = 0 || counter1 != 10, ++counter1)
		{
			printf("Enter an expected activity time: ");
			scanf("%d", array1[counter1]);
			
			return;
	}
}
Do you mean to check if counter1== 0 (equality), not to assign 0 to counter1?

while (counter1 = 0)


Since you have a fixed number of iterations to fill the elements of the array, you can use a for loop to go through each element. Something like this...

1
2
3
4
5
for (int counter=0; counter<arraySize; counter++)
{
     cout<< "Please enter data: ";      
     cin >> myArray[counter];
}
Topic archived. No new replies allowed.