Identifier not found

Okay, so I'm really new to C++
This will become really evident as you keep reading.

So i keep getting the error "error C3861: 'inputCheck': identifier not found"

with this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace 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();}
	else if (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.
Place the function definition before main().
You need to declare the function before it is used. Otherwise the compiler sees that line and goes "what is that?".

Use the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace 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();}
	else if (input == "Start"){gameStart();}
	else {cout<<"Please type start to begin: ";}

}


Or the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace 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();}
	else if (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();


}

@Stewbond

Tried the second solution already and it gave me a different error, haven't tried the first solution so I'll try that.

Edit: They both return the same error "(function name) must return a value"
Says it for both functions in both solutions.

@wjee0910

I had figured as much. But thanks for a reply.
Last edited on
Should I put them in a separate .cpp file and do an include of those files?
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.
@Stewbond
Very nice answer!

@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/

Good luck!
That worked! thanks guys! :)
Thanks Duoas

Now Dreijj, lets start with you inputCheck() function:

1
2
3
4
5
6
7
int inputCheck(){

	if (input == "start"){gameStart();}
	else if (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();}
	else if (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.
Topic archived. No new replies allowed.