Create a program that will generate randomize number that will store as the element inside the array. The system will display the 1st and 2nd highest number and the 1st and 2nd lowest number.
This is my code so far... I'm having a hard time to make the output display the first and 2nd highest number and the 1st and 2nd lowest number.
int main()
{
srand(time(0));
int size = 10;
int arr [ 10 ];
cout << "The numbers in the array are: " << " ";
for (int i =0; i < size; i++ )
{
arr[i]= (1 + rand() % 100000000);
cout << arr [ i ] << " " ; }
cout << endl;
cout << "The largest item is " << max <<"and it is at memory location:" <<memory location <<endl;
cin.get();
system("pause>0");
return 0;}
Please help me finish this code correctly. I appreciate your help.
cout << "The largest item is " << max <<"and it is at memory location:" <<memory location <<endl;
Surely this wasn't a serious attempt?
Anyway, I won't do your homework for you but really helps in writing programs is breaking it up into manageable tasks. You've filled the array correctly, right? After that you can either iterate through and find the two smallest/biggest numbers, or you can sort the array and just grab the two top/bottom elements of the array.