I sorta need help getting the minimum I keep getting thirteen can some one help me out? The issue I believe is I'm not showing the formula for low n line I'm confused I have tried to switch out the values for the array and I can't figure it out just if someone could explain to m please.
#include <iostream>
using namespace std;
int getHighest(int numArray[], int numElements);
int getLowest(int numArray[], int numelements);
int main()
{
int numbers[4] = { 13, 2, 40, 25 };
cout << "The highest number in the array is " << getHighest(numbers, 4) << "." << endl;
cout << "The lowest number in the array is "<< getLowest(numbers,0) << "." << endl;
return 0;
}
int getHighest(int numArray[], int numElements)
{
int high = numArray[0];
for (int sub = 1; sub < numElements; sub += 1)
if (numArray[sub] > high)
high = numArray[sub];
return high;
}
int getLowest(int numArray[], int numElements)
{
int low = numArray[0];
for (int sub = 0; sub >= numElements; sub--)
if (numArray[sub]< low)
low = numArray[sub];
return low;
}
for(int sub=0; sub >= numElements; sub--)What wouldsubbe in each iteration? withnumElementsbeing0your for loop only runs once. Hence, the output 13.getLowest(numbers,0). The 2nd parameter provides the number of elements (of the array in the 1st parameter). That's in your case4as you did ingetHighest(numbers, 4).sub--you DEcrement your loop index. (sub--could be written assub -= 1orsub = sub - 1as well.) Hence, you have to start with the highest possible index, and you have to check whether index is still>= 0in the loop condition. Sloppy spoken, you go backwards through your array. So, you have to start at the end of it.