-
Undefined Function...
Ok here is the code for the very beginning of my program.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <windows.h>
using namespace std;
void create();
// This makes the create function, which allows me to use the creatdata funtion.
void createdata(string rac);
// Creates character data, after character is created.
void menu();
// Allows game menu to show up.
void story();
// Begins story.
void adventure1();
// Starts you on your travels.
void cleft();
// Chose to go left in adventure1
void cright();
// Chose to go right in adventure1.
void cdry();
// You entered the cave in RIGHT.
void cwet();
Ive used all those functions so far. It says that create(), creatdata(string rac), menu(), and story() all work. Yet, it says that adventure1(), cleft(), cright(), cdry(), and cwet() are undefined. I cant seem to figure out why. That right there shows them being defined doesnt it?
-
Well... those are prototypes... did you define them at the end of your program?
Code:
void foo(); // This is a function prototype
int main() {
foo(); // This is a function call
return 0;
}
void foo() {
cout << "This is a function definition.";
}
If you did define them, then let me see your funtion calls as you might not be calling them properly.
-
Well here is how I used them:
Code:
//iostream, with voids and whatnot.
int main() {
//.................
void create() {
// In here I used an if statement so say:
if (yn == "y" || yn == "Y")
{
cout << "Data Created.\n"
createdata();
menu;
}
}
void menu(){
// Bascially the same as create() but with different questions, and stuff.
}
// Rest of program uses adventure1(), cright(), cleft(), cdry(), and cwet() basically the same way.
If that wasnt a good discription, let me know.
-
Are you implying that you're defining the function inside of main? That's not legal. Also the function call to menu is incorrect in your create function. Please paste you actual code rather than writing some quick rewrite that has more errors in it than your actual code.
-
Here is a direct copy of my program including the voids at the top and part of void create() inside of main.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <windows.h>
using namespace std;
void create();
// This makes the create function, which allows me to use the creatdata funtion.
void createdata(string rac);
// Creates character data, after character is created.
void menu();
// Allows game menu to show up.
void story();
// Begins story.
void adventure1();
// Starts you on your travels.
void cleft();
// Chose to go left in adventure1
void cright();
// Chose to go right in adventure1.
void cdry();
// You entered the cave in RIGHT.
void cwet();
// You walk in the rain in RIGHT.
void adventure2();
// Sixth part of adventure.
void adventure3();
// Seventh part of adventure.
void adventure4();
// Eight part of adventure.
void adventure5();
// Ninth part of adventure.
void adventure6();
// Final adventure.
void ending();
// Final text display in game, before credits.
void credits();
// Credits appear on screen.
int main(){
string select;
SetConsoleTitle("Rise of Darkness v1.0");
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
do
{
cout << "Welcome to the great world of Darkonia!\n";
cout << "Please select an option below to start your quest.\n\n";
cout << "Create Character [press C]\n";
cout << "Game Info [press I]\n";
cout << "EXIT [press X]\n";
cin >> select;
cout << endl;
if (select == "c" || select == "C")
{
create();
}
else if ( select == "i" || select == "I")
{
cout << "You play as the young Riako. You average eveyrday\n";
cout << "medieval knight. Your set on the task of finding\n";
cout << "the great Scroll. Do you have what it takes to survive\n";
cout << "the journey, slay the beasts, grab the scroll and make it back?\n";
cout << "If you think so, create your character type and being.\n\n\n";
cout << "No matter what race you make, it is a male and his name is\n";
cout << "Riako. Creating the character was just a little practice with code.\n\n\n";
}
else if (select == "x" || select == "X")
{
break;
}
else
{
SetConsoleTextAttribute(hOut,
FOREGROUND_RED |
FOREGROUND_INTENSITY);
cout << "Sorry, that is not a proper selection. Please choose again.\n\n\n\n" << endl;
SetConsoleTextAttribute(hOut,
FOREGROUND_RED |
FOREGROUND_GREEN |
FOREGROUND_BLUE);
}
}while (select != "x" || select != "X");
}
void create() {
string rac; // Used to choose a race
string yn; // Used to choose whether or not to use the chosen race.
cout << "Welcome to Character Creation.\n";
cout << "Select a character race.\n\n";
cout << "Human (press H)\n";
cout << "Elf (press E)\n";
cout << "Werewolf (press W)\n";
cout << "Dwarf (press D)\n";
cin >> rac;
cout << endl;
if (rac == "h" || rac == "H")
{
cout << "Humans specialize in stubborness.\n";
cout << "Since the humans are so stubborn they are able to\n";
cout << "fight hard and long. Although, humans have soft skin\n";
cout << "and fragile bodies, this makes them supceptable\n";
cout << "to lots of damage. To protect a human, money is required\n";
cout << "to buy armor and weapons.\n\n\n";
cout << "Are you sure you want to be a human? Y/N:";
cin >> yn;
if (yn == "Y"|| yn == "y")
{
cout << endl << "Data created.\n\n\n";
createdata(rac);
menu();
}
else
{
create();
}
cin.get();
}
It said that the create() was fine. Thats why I dont really get why the other couple of functions dont work.
-
Where are the other functions? Are you imagining that you defined them?
-
No, that was just a chunk out of it.
In it, shows how I used create(), and it worked fine. Like here:
Code:
if (select == "c" || select == "C")
{
create();
}
Also here where I used menu(), and createdata()..which both work fine.
Code:
if (yn == "Y"|| yn == "y")
{
cout << endl << "Data created.\n\n\n";
createdata(rac);
menu();
}
Also, dude if your making fun of me or something...I dont appreciate that as ive only been programming since like last Thursday night. My friend taught me most of what I know, and a few things I just looked at briefly. Im trying to make a short text based game, with what i know. I know enough to make it, I just need some help with this part and my firned isnt availbe right now. He might not be for a while as well.
-
I'm not making fun of you, but you're asking a question about why some piece of code isn't working, yet the only code you've shown me so far is that part that is working. So where's the logic in that? You can't show me working code and then say "...and by the way the part that doesn't work is the same" and expect me to believe that it exists and doesn't work.
-
You need to post a COMPLETE program which is shorter than what you have at present, and which still demonstrates the problem.
Simply copy/pasting random bits of the code you have just isn't going to work.
-
Well im not sure what to show you. It just says linker error so im not really sure where I didnt use the functions correctly. Here is the adventure1(), when the player presses R it will bring up cright() and when they press L it should bring up cleft().
Code:
void adventure1();
{
string rl;
cout << "You begin your travels alone. All you have with you is a small amount\n";
cout << "of bread, and a few containers of water. After walking for several\n";
cout << "hours, you come to a fork in the road. There lay two pathes ahead.\n\n";
cout << "The path to the left looks very pleseant and happy.\n";
cout << "The path to your right seems very grimy, and dead.\n\n";
cout << "Which direction do you choose? Right(press R) or Left(press L)?\n\n";
if (rl == "R" || rl == "r")
{
cout << "You have chosen to take the path to your right. You\n";
cout << "turn right and start walking again.\n";
cright();
}
else (rl == "L" || rl == "l");
{
cout << "You have chosen to take the path to your left. You\n";
cout << "turn left and start walking again.\n";
cleft();
}
}
Like I said, I dont really no where I used it wrong. So if this doesnt help...I dont know what else I can show you.
-
> void adventure1();
Get rid of that ;
> else (rl == "L" || rl == "l");
Else doesn't have a condition, and it doesn't have a ; either.