I'm working with structs, and I'm trying to make an array to hold the data and cout it, but I'm not doing something correctly. I have no experience with structs and I honestly have no idea what could be wrong here. Would someone point me at the problem please?
It is homework, but it's an effort grade. I just need to understand.
No, you are doing some things correctly, just not everything. :-)
When you read the LegLength with cin >> you are leaving the newline behind in the input buffer, so the next getline(cin,...) will read an empty line.
Try adding this after the cin >> Frogs[i].LegLength;
Ahhhh. That's right. I forget very easily you have to be very careful with getlines and extraction operators in conjunction.
Just to further help me understand that madness, would the get() function for eating up a single char be useful in such a situation too? Or is that for different situations?
int main()
try
{
Frog frogs[MAX_SIZE];
int nfrogs;
cout << "How many frogs do you want?" << endl;
readline( cin, nfrogs );
for (int i = 0; i < nfrogs; i++)
{
cout << "What is the name of Frog " << (i+1) << "? ";
readline( cin, frogs[i].Name );
cout << "What is the age of Frog " << (i+1) << "? ";
readline( cin, frogs[i].Age );
cout << "What is the length of Frog " << (i+1) << "? ";
readline( cin, frogs[i].LegLength );
}
// and so on...
}
catch (...)
{
cerr << "Aaaiiiiiiiiiii!\n";
return 1;
}