I am trying to create a program that asks a user how many babies they have, gather input about each baby, and then displays it on the console. I am 90% of the way there but I am stuck.
The input/output on the console should look like this;
Please enter the number of babies: 2
Please enter baby #1's height : 21.5
Please enter baby #2's height : 19.75
Baby #1's info: Height: 21.5 inches
Baby #2's info: Height: 19.75 inches
The output for my code keeps showing 19.75 as the height for both babies. I realize I probably need to use a pointer to dynamically allocate different values to aBaby.height, but I haven't used a pointer within a structure before. Any help would be greatly appreciated.
#include <iostream>
using namespace std;
struct Baby {
double length;
};
int main ()
{
int iNumBaby = 0;
cout<<"Please enter the number of babies: ";
cin>>iNumBaby;
cout<<endl;
Baby aBaby;
Baby* pBaby = new Baby[iNumBaby];
for(int i = 0; i < iNumBaby; i++)
{
cout << "Please enter baby #"<< i + 1 <<"'s height <inches>: ";
cin >> aBaby.length;
cout << "\n";
}
for(int i = 0; i < iNumBaby; i++)
{
cout << "\Baby #"<<i + 1<<"'s info:\n";
cout << "Height: " <<aBaby.length<<" inches"<<endl;
cout << "\n";
}
system("PAUSE");
delete[] pBaby;
return 0;
}