keep getting min of array 0

I am trying to find the min and max values of an array. For some reason the output gives me 0 for the min, any help is greatly appreciated.

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
float score[10];
int max=score[0];
int min=score[0];
int x;

for (x=0; x<=9; x=x+1) {
cout<<"Enter the score""\n";
cin>>score[x];
}

for (x=0; x<=9; x=x+5) {
cout<<score[x]<<" "<<score[x+1]<<" "<<score[x+2]<<" "<<score[x+3]<<" "<<score[x+4]<<"\n";
}

for (x=1; x<9; x++)
{
if (score[x]>max)
{ max=score[x];
}

else if (score[x] < min)
{
min= score[x];
min= x;
}

}
cout<<"the biggest number is "<<max<< endl;
cout<<"the smallest number is "<<min<< endl;
return 0;
}
Why is the min/max int when the scores are floats?

Also score[0] is undefined when you initialize the min/max. You should do that after getting the user to enter the scores. You can also directly check the min/maxes there.


Basically you would want to do something like:

1
2
3
4
5
6
7
8
9
10
11
12
const int scores = 10;
float score[scores];
float min = 100.0f; //largest possible
float max = 0.0f; //lowest possible

for(int i = 0; i < scores; ++i)
{
    cout << "enter score: ";
    cin >> score[i];
    if(score[i] > max) max = score[i];
    if(score[i] < min) min = score[i];
}
thank you for the assistance learning all of this by myself sometimes stuck and and need to be pointed in the right direction such a great help!!
Topic archived. No new replies allowed.