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;
}
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;