Having an error with my if statement (ISO C++ forbids comparison between pointer and integer [-fpermissive])

It says i haven't declared God in the scope

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
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
   int name;
   cout << "Type your name here: ";
   cin >> name;



   if (name == God)
   {
       cout << "Hey God" << endl;

   }

       else

 {
     cout << "You're lying" << endl;
 }
  system ("PAUSE");
   return 0;
   }

Last edited on

Your testing against God without quotes, and without quotes the compiler thinks its another variable.

use "God" on line 14

I did that, then i get this: ISO C++ forbids comparison between pointer and integer
correct because you declared name as an int, it should be either a string or array of chars.

http://www.cplusplus.com/doc/tutorial/variables/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string name;
	cout << "Type your name here: ";
	cin >> name;

	if (name == "God")
		cout << "Hey God" << endl;
	else
		cout << "You're lying" << endl;

	return 0;
}
Last edited on
How would it be done with an array of chars?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <iostream>
using namespace std;

int main()
{
	char name[50];
	cout << "Type your name here: ";
	cin >> name;

	if (strcmp(name,"God")==0)
		cout << "Hey God" << endl;
	else
		cout << "You're lying" << endl;

	return 0;
}


strcmp: http://www.cplusplus.com/reference/cstring/strcmp/
So this might be the dumbest question you've ever heard. Im very new to C++ and i was wondering; is C++ programs only executed in cmd? If not, how can you change it?

No not dumb at all.

There is no limit to what you can do with C++. For example, the Windows operating system is written in it, most Windows applications are written in it, and most commercial games are written in it.

The cmd (or console I presume you mean) is ideal for learning the C/C++ language and once you are comfortable with C++ you then move on to learning Windows programming (assuming your on Windows) using the various API/Frameworks around.

If you are a beginner then I wouldn't suggest trying Windows programming just yet.
God should be a string which is have to be inside of double quote
Topic archived. No new replies allowed.