Logical operator problems when entering integer to char variable

Can somebody explain why it is that problems arise here. Fx if I type a=1 I get "More" as an output and if a=2 the output is also "More".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
#include <math.h>
#include <fstream>
#include <string>
using namespace std;

int main(){
	char a;

	cin>>a;

	if(a==1){
		cout<<"One";
	}
	else if(a>3){
		cout<<"More";
	}
	else{
		cout<<"Hmm";
	}

	return 0;
}
The input expected is just a single char, so if you type "a=1" as your input, that's not just a single char. That's three chars.

(a==1) Here, 1 is the number 1. I expect you actually want the char '1'. 1 is not the same as '1'. 1 is a number. '1' is a char.
Topic archived. No new replies allowed.