Hi, I\'m writing a program in C++ that takes an [8] value array from a file and
ID: 3650025 • Letter: H
Question
Hi, I'm writing a program in C++ that takes an [8] value array from a file and computes the max value.The array is {10.5, -5.3, 14.27, 0.02, 763.291, -101.2, 67.00, 1.0}.
I have everything working except that when I compute the max value I get -101.2. Clearly, to the compilers eyes this is the max value.
So, how do I account for the negative values in the array? The answer should be 763.291.
My code so far to compute the max:
double getMax(double Values[], int i)
{
double max = Values[i];
do {
for (i = 0; i < 8; i++)
{
if (Values[i] < max)
max = Values[i];
}
} while (max >= 0);
return max;
}
I tried to skip the negatives with a do-while loop but it never worked. :|
Passing the int i to the function probably wasn't necessary.