How to define an identifier

This is my 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
#include <iostream>
#include <string>

using namespace std;

string subject;
string question;

int main()
{
	ask;
	close;
}

int ask()
{
	cout << "ask";
	getline (cin,subject);
	cout << "output " << subject << endl;
	cout << "repeat?";
	getline (cin,question);
	close;
}

int close()
{
	if (question == "yes")
	{
		ask;
	}
	else return 0;
}

VC++ says
1
2
3
4
main.cpp(11): error C2065: 'ask' : undeclared identifier
main.cpp(12): error C2065: 'close' : undeclared identifier
main.cpp(22): error C2065: 'close' : undeclared identifier
main.cpp(29): warning C4551: function call missing argument list
What do you want ask and close to be? Integers? In that case int ask; int close;
Actually, I think Mr. Chance would like to call those two functions. That said, he's missing a few things...

@OP
You need to declare ask() and close() before the place where you call them. In your case, you need to declare them before main().

Second, you forgot the parentheses after ask() and close() when you called them in your functions. :)

Happy coding!

-Albatross
Last edited on
Thanks, but now I get:
1
2
main.cpp(24): error C4716: 'ask' : must return a value
main.cpp(33): warning C4715: 'close' : not all control paths return a value


New 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 <string>

using namespace std;

string subject;
string question;

int ask();
int close();

int main()
{
}

int ask()
{
	cout << "ask";
	getline (cin,subject);
	cout << "output " << subject << endl;
	cout << "repeat?";
	getline (cin,question);
	close();
}

int close()
{
	if (question == "yes")
	{
		ask();
	}
	else return 0;
}
Last edited on
1
2
int // <---
ask()
If you don't want to return a value declare it as void ask();
There is nothing in main...
Last edited on
Also for close:
1
2
3
4
5
6
7
8
int close()
{
	if (question == "yes")
	{
		ask();
	}
	else return 0;
}

since it's expected to return an int it should return one in all cases. For example
1
2
3
4
5
6
7
8
9
int close()
{
	if (question == "yes")
	{
		ask();
                return 1; //it returns a value even if question is "yes"
	}
	else return 0;
}
Thanks. It's working now.
Topic archived. No new replies allowed.