Wrong output for C++ code

I am a newbie to all of this, trying to learn on my own. This is revised code that others had helped me with.

This code is STILL giving me some wrong output.

1. It gives the maxHeight but not the minHeight of the five students.
2. It does not give me the number of girls or number of boys.
3. It does not give me the average girl's height.

This is an update from prior code.

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{

int height[5];
char gender[5];
int userNumber = 0;
int totalHeight = 0;
int maxHeight = 0;
int minHeight = 0;
int avg = 0;


for (int studentNum = 1; studentNum <= 5; studentNum++)
{
cout << "Enter Student " << studentNum << "'s height: ";
cin >> height[userNumber];
cout << "Enter Student " << studentNum << "'s gender [M,m,F,f]: ";
cin >> gender[userNumber];

userNumber++;
}


for(int count=0;count<5;count++)
{
totalHeight=totalHeight+height[count];
totalGirlsHeight=totalGirlsHeight+height[count];

if (height[count]>=maxHeight)
maxHeight=height[count];

if (height[count]<=minHeight)
minHeight=height[count];

if(gender[count]=='F') girls++;

if(gender[count]=='M') boys++;
}
avg = totalHeight/5;
favg = totalGirlsHeight/girls;

cout << "The tallest student is " << maxHeight << " and the shortest student is " << minHeight << endl;
cout << "The average height of all students is " << avg << endl;
cout << "The number of female students is " << girls << endl;
cout << "The number of male students is " << boys << endl;
cout << "The average height of female students is " << favg << endl;

cout << "The student heights and genders you entered are: "<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << height[x] << endl;
cout << gender[x] << endl;
}

ofstream studentHeights;
studentHeights.open("heights.txt", ios::out);

if (studentHeights.is_open())
{
for (int count = 0; count < 5; count = count + 1)
{
studentHeights << height[count] << endl;
}
studentHeights.close();
}
else
{
cout << "The file could not be opened." << endl;

}


system("pause");
return 0;
}
You made another thread for the same problem, deleted the contents of the old one and still don't use [code] tags. That's a bit irritating..
1. you initialize minheight to 0 and no height is less than 0.
2. maybe you enter 'm' and check with 'M' ? also, where are girls, boys declared?
3. that comes from 2 and also because girls is probably an integer and integer division rounds down.
Topic archived. No new replies allowed.