four digit unlock code

I have written a simple code that prompts user for an code to unlock the rest of the program. My problem is it only allows me to use a single digit. I'm using the following coding to get this

[/code]
int main ()
{
char operation;
cout << "input code" << endl;
cin >> operation ;
switch (operation)
{
case '2':
cout << "Hello Bob."<< endl;
break;
case '4':
cout << "Hell Leeroy." <<endl;
default:
cout << "Invalide code"<< endl;
cout << "Program terminated"<< endl;

I have tried using
int operation
int long operation
int long long operation
Instead of the char operation thinking that because it was a longer number it needed to have the long after it to recognize the longer code input but neither has worked.
What am I doing wrong?
Please direct me to the proper portion of the tutorials to complete the portion of the code.
You just have some syntax errors:

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
	int operation;
	
	std::cout << "Input code: ";
	std::cin >> operation;
	std::cout << std::endl;

	switch (operation)
	{
	case 1234:
		std::cout << "1234" << std::endl;
		break;
	case 4321:
		std::cout << "4321" << std::endl;
		break;
	default:
		std::cout << "Debug" << std::endl;
	}
	return 0;
}
char is one character
try using :char operation[5]
the 5 is because this is a string and the program will end it with '\0'
(or char operation[4] and you input each character alone like
1
2
for(i=0;i<4;i++)
    cin>>operation[i];


however int should be enough could you show us the program that didn't work with int
I think u mean that the code is not written correctly when You say a syntax error. I didn't include all the code.
I'm using the line
using namespace std;
with in my header so I don't have the std out things u have. A syntax error wood cause the code not to compile, correct?
As for the link you provided I'm checking in to how the if statements work in the examples there to try to implement them in to my code. Thanks for the link.
Topic archived. No new replies allowed.