im having problems finding the minimum value from an array plz help, heres my code:
#include<iostream>
using namespace std;
int main()
{
const int num = 9;
float avg = 0;
float sum = 0;
float max = 0;
float min = 0;
float myArray[9];
for (int x = 0; x<num ; x++)
{
cout << "Please enter the " << x << " number.." << endl;
cin >> myArray[x];
}
for(int x = 0; x<num; x++)
{
sum += myArray[x];
avg = sum/num;
if (myArray[x] > max)
{
max = myArray[x];
}
if (myArray[x]<min)
{
min=myArray[x];
}
}
cout <<"The Highest value in the array is " << max << endl;
cout << "The lowest value in the array is " << min << endl;
cout << "The average of the array is " << avg << endl;
return 0;
}
So you start with a min value of zero. What happens if all the numbers you enter are above zero? Can you think of a better number to set min to at the start?