Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

Explanation / Answer

#include 02 #include 03 #include 04 05 using namespace std; 06 07 int main() 08 { 09 // Variables 10 bool correctGuess = false; 11 int num1, num2, lo, hi, randNum, guess; 12 int numGuess = 0; 13 14 // Get/Test inputs 15 cout > num2; 17 18 if (num1 > num2) 19 { 20 lo = num1; 21 hi = num2; 22 } 23 else 24 { 25 lo = num2; 26 hi = num1; 27 } 28 29 // Random number time 30 srand (time(NULL)); 31 randNum = (rand()%(hi-lo))+ lo; 32 33 cout randNum) 44 { 45 cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote