#include <iostream>
using namespace std;
int main()
{
double sixty = 0.0;
double fiftyfive = 0.0;
double height[10];
double tallest = 0.0;
double shortest = 0.0;
double average = 0.0;
double total = 0.0;
for (int x = 0; x < 10; x = x + 1)
{
height[x] = 0.0;
}
cout << "Please enter the heights of ten students. "<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << "Enter height of a student: ";
cin >> height[x];
}
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] > 60)
{
sixty = sixty + 1;
}
}
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] < 55)
{
fiftyfive = fiftyfive + 1;
}
}
cout << "The number of students over 60 inches in height: " << sixty << endl;
cout << "The number of students under 55 inches in height: " << fiftyfive << endl;
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] > tallest)
{
tallest = height[x];
}
}
cout << "The tallest student is: " << tallest << endl;
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] < shortest)
{
shortest = height[x];
}
}
cout << "The shortest student is: " << shortest << endl;
for (int x = 0; x < 10; x = x + 1)
{
total = total + height[x];
}
average = total / 10;
cout << "The average student height is: " << average << endl;
system("pause");
return 0;
}
In the above, I need to spit out the # of students over 60in, the # of students over 55in, the average height, the tallest height, and the shortest height.
Everything works fine except for the shortest height. I return an output of zero for that portion of the code.
This is simple code so I imagine it's a simple problem which I'm overlooking. Any input is appreciated.