Help with array user input mode

Hi,
help me with array, how I can create array with user input mode with keyboard.
I understand with random, but don't understand user input mode. :(
please help me:

This is random:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>

#define N 5

int main()
{
int array[N], i ;

srand(time(NULL));
printf("\nArray\n");
for(i=0; i<N; i++)
{

array[i]=rand()%20 - 10;
printf("%4d", array[i]);
}
//printf("%4d", array[i]);
//printf("\n");

getch();
return 0;
}
Last edited on
Why are you doing this in C?

Woah... Loads of bad C++ things to do in there. Especially this: #define . Please use something like this: const int N = 5;

Anyway, using C++, getting user input for an array isn't difficult.

1
2
3
4
5
6
7
8
int a;

for(int i = 0; i < N; i++)
{
     cout << "Enter #" << (i+1) << ": ";
     cin >> a;
     arr[i] = a;
}


Anyway, clean up that code, or if you want to do C, go to a C forum.
Thanks! Its work! :) Now I understand system.
Topic archived. No new replies allowed.