#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
usingnamespace std;
string input;
int inventory [5];
int charName;
int main(){
cout<<"\n\n"<<endl;
cout<<"Welcome to...\n";
cout<<"Please type start to begin: ";
cin>>input;
inputCheck();
}
int gameStart(){
system("Pause");
//empty except for the pause for now so I can see if it will even get this far
}
int inputCheck(){
if (input == "start"){gameStart();}
elseif (input == "Start"){gameStart();}
else {cout<<"Please type start to begin: ";}
}
I'm confused because when I googled the error it says that means the function is undefined. And I definitely defined the function. Any help is appreciated.
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
usingnamespace std;
int inputCheck(); //Declaration added here.
int gameStart(); //and here
string input;
int inventory [5];
int charName;
int main(){
cout<<"\n\n"<<endl;
cout<<"Welcome to...\n";
cout<<"Please type start to begin: ";
cin>>input;
inputCheck();
}
int gameStart(){
system("Pause");
//empty except for the pause for now so I can see if it will even get this far
}
int inputCheck(){
if (input == "start"){gameStart();}
elseif (input == "Start"){gameStart();}
else {cout<<"Please type start to begin: ";}
}
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
usingnamespace std;
int gameStart(){
system("Pause");
//empty except for the pause for now so I can see if it will even get this far
}
int inputCheck(){
if (input == "start"){gameStart();}
elseif (input == "Start"){gameStart();}
else {cout<<"Please type start to begin: ";}
}
string input;
int inventory [5];
int charName;
int main(){
cout<<"\n\n"<<endl;
cout<<"Welcome to...\n";
cout<<"Please type start to begin: ";
cin>>input;
inputCheck();
}
First, move main() to the end of the code, immediately following inputCheck().
Then, change the return type of both auxiliary functions from int to void.
@Drejj
If your function starts with "int" then it should return an integer value. If your function does not return anything, it should start with "void".
Be sure to read up on functions here: http://www.cplusplus.com/doc/tutorial/functions/
Now Dreijj, lets start with you inputCheck() function:
1 2 3 4 5 6 7
int inputCheck(){
if (input == "start"){gameStart();}
elseif (input == "Start"){gameStart();}
else {cout<<"Please type start to begin: ";}
}
At the start of the first line here, you use the type int. This means that we need to return an integer. For example, if we wanted to return a random number between 1 and 10:
function:
1 2 3 4 5 6
int get_rand() //Function is defined as an int
{
int i; //Lets declare a variable we intend to return later
i = (rand() % 10) + 1 // Lets set this variable to something (number between 1 and 10?)
return i; // Now lets return this number
}
Now we can use it in our main function:
1 2 3 4 5 6 7 8
int main()
{
int MyNumber;
MyNumber = get_rand(); //Calling the function will set MyNumber to a random number between 1 and 10
cout << MyNumber;
return 0;
}
In your case, you probably just want to make your functions type void. This means that they do not have to return anything (manually) or can return nothing.
example:
1 2 3 4 5 6 7 8
void inputCheck(){ // note our type is void, this means it is not expecting a value at the end.
if (input == "start"){gameStart();}
elseif (input == "Start"){gameStart();}
else {cout<<"Please type start to begin: ";}
return; //This line is optional as the compiler will add it automatically in a void function.
}
Yep, fixed it. Also, wasn't getting an error for this but i altered my inputCheck function so that way it actually re-requests the input instead of just prompting it. Not exactly relevant I guess but oh well.