Share this post

Link to post

Share on other sites

That's because you have to define a function before you call it. That means you either need to have a function prototype before it's first use, or it needs to actually be defined before you call it. Local function definitions are illegal which is why you got the error you were getting.

This is all very basic C++ syntax stuff that is covered in virtually any book about how to program in C++. I would recommend picking one up as they will have the answers for you in hard ink so you don't have to post here hoping someone will get back to you for an issue as basic as this.

/***************************************/Function: "battle"/Purpose: To print to the screen, and validate that the function is being called correctly,/ and show that the "character" variable does in fact contain the user's input/**************************************/void battle(){ cout << " i guess it works " << character << "\n" << endl;}

Every function that you write in the program must have a declaration, which you see in the Prototypes area. The declaration doesn't call the function, it defines it, so that the compiler knows what the function should expect and/or return when the function is actually called later. Notice that function prototypes must end with a ";". The actual function is called inside of main, and the actual function implementation is below the main function.

After moving the declaration above the main function, about the only way I could see a "not declared" error popping up is if you forgot to add the ";" onto the prototype.

Secondly, notice I changed the character variable to a string, and not an int (int is an integer, which has no way possible to hold a string of characters). If left as an int (integer), the input would not be read correctly and you would get unexpected results. You can use a string with the standard std::cin, std::cout just as easily as an integer.

Just as a side note, try to force yourself to comment your code when you can. It helps you understand things better when you look at it later, and it doesn't actually get compiled with the code, so it doesn't make your program any larger at all.

Hope this helps :)Scorp

EDIT -- Can someone please tell me how to use the -source- tag correctly in the forums here? I would use it here, but when I do, it converts every> and < into the & lt ; and & gt ; equivalents, which really hoses things up :/

0

Share this post

Link to post

Share on other sites

Original post by TFS_ScorpionEDIT -- Can someone please tell me how to use the -source- tag correctly in the forums here? I would use it here, but when I do, it converts every> and < into the & lt ; and & gt ; equivalents, which really hoses things up :/

Copy the code you want in the source tags before you go into edit mode. This is just another thing GameDev apparently put in.

0

Share this post

Link to post

Share on other sites

That's what I do normally, but in a case where I c/p code over from the IDE and into a post, it doesn't work for me. I'm sure there's a way around it, but can't figure it out. I'm going to use this post for a moment and experiment... then change it completely into a formal reply and what worked if I find it :)

Scorp

EDIT -> Well... either I was smoking something last night and can't figure out what I did different, or my luck is just better today, as it works fine today. Maybe there was a ghost in the machine last night... anyhoo, it works now, so disregard, and thanks :)