arrays

I was wondering if you could please help with my coding. Ive been trying for hours but cannot find my error. here is my code. I will really appreciate your help.

problem: Research shows that children in this age group are expected to grow 5% taller in one year. Write a program to do the following. Create two 10-element arrays, one to store the current heights and the other one to store the expected heights after a 5% growth. Ask the user to enter the current heights and store them in one array. Calculate the expected heights and store them in the other array. Display the current heights and the expected heights of the students.

this is what I have

#include <iostream>

using namespace std;

int main ()
{
double height [10];
double expectHeight = 0.0;



for (int x = 0; x < 10; x = x + 1)
{
height[x] = 0.0;
}


for (int x = 0; x < 10; x = x + 1)
{
cout << "enter current height of child " << x + 1 << " : ";
cin >> height[x];

expectHeight = height[x] * .05 + height[x];
}
cout << " The expected height of the children " << endl;



for (int x = 0; x < 10; x = x + 1)
{
cout << " Child " << x+1 << " Height " << height[x] << " Expected height " << expectHeight << endl;
}

system ("pause");
return 0;
}
Well your expectHeight variable is just set to whatever the last index in your for loop sets it to.

The assignment looks like it wants you to create another array to store the expected height for each child, so I would create an expectHeight array to store the values for each index.
Thank you so much. I finally got it to work. Could you also help me on this question??

A 5th grade teacher has measured the height (in inches) of 10 students in her class. Write a program that uses a loop to read the heights from the keyboard and store the heights in an array. Find and display the height of the shortest student in the whole class.

This is what I have so far.

#include <iostream>

using namespace std;

int main()
{
int height [10];
int Min = 0;

for(int x = 0; x < 10; x= x + 1)
{
height[x] = 0;
}
cout << "You are asked to enter heights of 10 students. " <<endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << " Enter height of a student: ";
cin >> height[x];


if (height[x] < Min)
height[x] = Min;
}

cout << " Height of shortest student is " << Min << endl;

system ("pause");
return 0;
}
Well first off you should initialize Min to something higher than 0, since I doubt anyone is shorter than 0 inches lol.

Next, in your if statement you have it right except it should be:
1
2
3
if (height[x] < Min)
Min = height[x];
}

You're printing out Min, so you want to change the value of Min to the shortest student, not change the value of the shortest student to Min
Thank you so much!!!!
Topic archived. No new replies allowed.