1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
class fatty {
public:
int i;
string name [8] ;
int pancakes [8] ;
void getcake ()
{
cout << "the fat bastard called "<< *name <<" ate "
<< *pancakes << "pancakes!!"<< endl;
}
void eatcake ()
{
cout << "whats the fatties name?" << endl;
cin >> name [0];
name [i++];
cout << "how many cakes has he had? " << endl;
cin >> pancakes [0];
1+pancakes [0];
}
};
|
Please use code tags - that's the
<>
button on the right.
On lines 4 and 5 of your class, you specify that each individual
fatty object will have no less than eight different names, and eight separate counts of pancakes eaten.
More than likely that is not what was intended, as function
eatcake only stores a value in the first occurrence. (By the way, lines 17 and 20 don't really do anything useful).
If we keep to the same class design for now, it follows that function
getcake should also access the first occurrence of each value too, like this:
cout << "the fat bastard called "<< name[0] << " ate " << pancakes[0] << " pancakes!!"<< endl;
But still, a more sensible solution is to get rid of all those arrays.
On the other hand, your
main() function could certainly use an array, something like this:
1 2 3 4 5 6
|
fatty fatties[8];
for (int i=0; i< 8; ++i )
{
fatties[i].eatcake();
}
|