- #1
Vagabond7
- 50
- 11
Homework Statement
Alright, so for my engineering programming class I have an assignment where I have to create a program with an array, and then do things with the array, such as create a search function for it, and list how many numbers fall within a certain range, ect, ect.
So I actually just need some help getting started on this particular assignment. I need to create an Array where the user inputs 20 numbers from the keyboard. Unfortunately all the examples we are given, the arrays have values already assigned to them. I have no idea how to let a user create the data for the area to be displayed.
Homework Equations
For example
int main()
{
/* use initializer list to initialize array n */
int n[ 10 ] = { 32, 27, 64, 18, 95, 14, 90, 70, 60, 37 };
int i; /* counter */
printf( "%s%13s\n", "Element", "Value" );
/* output contents of array in tabular format */
for ( i = 0; i < 10; i++ ) {
printf( "%7d%13d\n", i, n[ i ] );
} /* end for */
getch();
return 0; /* indicates successful termination */
All the values are given, and I know how to do that just fine. I have no idea how to let a user input the values for the array though.
The Attempt at a Solution
I tried some different things with scanf("%s", n); where "n" is the name of the array, but all the results always ended up wonky, giving me wild values once displayed that were definitely not anything I input.
How do I make an array where the values are put in by the user? The rest of the assignment I think I have a handle on, but every example involving arrays from our book, the values in the array are decided in the program itself. Thanks in advance.