anonymous
2011-11-30 16:22:21 UTC
a. Uses one loop to read the heights from the keyboard and store the heights in an array (use int as variable type) AND in addition read the student gender (‘M’ ‘m’ ‘F’ ‘f’ ) into a second array to store the gender (use char as variable type).
Suggested screen output :
Enter student 1 height:
Enter student 1 gender:
Enter student 2 height:
Enter student 2 gender:
Enter student 3 height:
Enter student 3 gender:
Etc..
The program should also:
b. Display the current height and the gender of each student.
c. Calculate and display the average height of the Female and the Male students.
d. Display the height of the shortest and tallest student in the whole class.
e. Display the count of Female and Male students.
f. Display the heights of the Female students only
g. Save the heights in the text file named heights.txt
Here is what I have so far but I keep getting an error
#include
using namespace std;
int main()
{
double height[10];
double gender = 0.0;
double sumHeight = 0.0;
double avgHeight = 0.0;
for (int x = 0; x < 10; x = x + 1)
{
height[x] = 0.0;
}
cout << "You will be asked to enter the height in inches and gender of 10 students."<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << "Enter students height " << x+1 << ": ";
cin >> height[x];
}
cout << "Enter students gender" << gender << ": ";
cin >> gender;
cout << "The height in inches and gender of 10 students: " << endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << "Height " << x+1 << ": high " << height[x] << " Gender: "<< gender << endl;
}
{
sumHeight = sumHeight + height[x];
}
avgHeight = sumHeight / 10;
cout << "The average student height: " << avgHeight << endl;
system("pause");
return 0;
}