this is my code:
and this is my error:Code:void Cat::Eat() { printf("\n%s ate.", name); } // ... other functions with same error
"Local Function Definitions are illegal."
What does that mean?
I'm using MSVC++7.
this is my code:
and this is my error:Code:void Cat::Eat() { printf("\n%s ate.", name); } // ... other functions with same error
"Local Function Definitions are illegal."
What does that mean?
I'm using MSVC++7.
Make sure you didn't leave out a closing brace. Otherwise, post some more code, please.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
I fixed THAT problem. I have another one, however. It happens somewhere in here:
the program crashes when I input the age. The age is an int.Code:int main() { // get name & set printf("What is the cat's name? "); scanf("%s",cat.name); // get age & set printf("\nWhat is the cat's age? "); scanf("%i",cat.age); // get weight & set printf("\nWhat is the cat's weight? "); scanf("&i",cat.weight); //printf("\nNAME: %s",cat.GetName()); printf("\nAGE : %i",cat.age); return 0; }
Why are you using scanf/printf with C++? You should be using cin/cout.
Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah
You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie
try using %d instead of %i
I came up with a cool phrase to put down here, but i forgot it...
I solved the input problem using "cin".
However, although I like C++ input (cin), I like C output (printf,etc.). It doesn't really matter, does it?
printf() is slightly faster, anyways.
what XSquared said.
But as for y it's crashing, i'd say because u need to pass cat.age's address.
scanf takes the address of an object, so
it doesn't crash on cat.name (assuming name is a string) because when using an identifier for an array it passes the address of the first element.Code:scanf("%i",&(cat.age));
That's right, Kyro! Darn! I always forget that scanf takes the adress. Silly me.