### Random numbers, Display the highest, second highest, and the lowest number.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include #include using namespace std; int main() { const int num = 10; int ran[num], high =0, high2, low = 16; srand(time(NULL)); //code to generate random numbers for (int i = 0;i < num;i++) { ran[i] = rand()%15+1; //the maximum number that will be generated is 15 } for (int i = 0; i < num;i++) { cout< high) { high2 = high; high = ran [count]; } else if (ran[count] > high2) high2 = ran[count]; if (ran[count] < low) { low = ran[count]; } } cout< 0"); return 0; }``````

the second highest number displays the duplicate of the highest if ever there is one.
Last edited on
 ``12345678910111213141516171819202122`` ``````int ran[num], high, high2, low; //... this code is skipped high = high2 = low = ran[0]; for ( int count=0; count < num; count++ ) { if ( high < ran[count] ) { high2 = high; high = ran [count]; } else if ( high2 < ran[count] ) { high2 = ran[count]; } else if ( ran[count] < low ) { low = ran[count]; } }``````
it still displays the duplicate.

ex set.
15 12 15 13 8 6 4 5 9 10

it displays

The highest number is 15
The second highest number is 15
The lowest number is 4

it should be like this:
The highest number is 15
The second highest number is 13
Last edited on
Topic archived. No new replies allowed.