| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
N00b question
I'm trying to write a C++ program that contains two arrays of 5 elements each. I'm trying to make one array that will initialize with random values, and the other array filled with data from the keyboard. The user input display keeps ending up with 0's for reason.
Thanks #include <iostream> #include <iomanip> #include <ctime> using namespace std; void fillRandomArray (int ary[], int size); void fillInputArray (int ary[], int size); void printArray (int ary[],int size); const int size =5; int array1[size]; int array2[size]; int main (int argc, char *argv[]) { fillRandomArray(array1,size); cout << "Display Random Number Array"; printArray(array1, size); cout << endl; fillInputArray (array1, size); cout<< "Display Input Number Array"; printArray (array2, size); system("pause"); return EXIT_SUCCESS; } void fillRandomArray (int ary[], int size) { srand (597); for(int i=0; i < size; i++) ary[i] = rand() % 25+1; return; } void fillInputArray (int ary[], int size) { cout <<"Enter 5 integer values: "; for (int i = 0; i < size; i++) cin>>ary[i]; return; } void printArray (int ary[], int size) { for(int i=0; i < size; i++) cout <<setw(5) <<ary[i]; cout << endl; return; } |
|
#2
|
|||
|
|||
|
fillInputArray (array1, size);
cout<< "Display Input Number Array"; printArray (array2, size);
__________________
Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > N00b question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|