Hello,
I need help displaying the Largest and Smallest numbers in my array. I don't know how to code it correctly. I was able to set up the array and get a sum and average to work. The problem section is labeled Largest and Smallest.
please help me output the largest and smallest numbers in the array. thank you in advance for your help.
@kaseyahumada
Here's one way. Declare ints max and low with the other declarations.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// **********************************************************
// Largest and Smallest
// **********************************************************
max = low = number[0]; // Sets values
for(lcv = 0; lcv < ARRAY_SIZE; lcv++)
{
if(low > number[lcv]) // Check if low is higher, and if it is..
low = number[lcv]; // Set low to number[lcv]
if(max < number[lcv]) // Check if max is lower, and if it is..
max = number[lcv]; // Set max to number[lcv]
}
cout << "Low = " << low << "\tMax = " << max << endl;
@whitenite1
thank you for you help with this problem of mine. I will now study your code and lean from it. thanks again for you help. have a blessed day.