Your problem is that your variables x and y are declared as type
char
. Type char is a single ASCII character, e.g. 'A', or '%' or '7'. So when you do
cin >> x;
the system reads the first character from the input, and stores that in X. If you enter '7', the ASCII value '7' is stored in x. The character '7' does not have a numerical value of 7, but of 0x37 or 55 decimal. so when num_for_map["Num 1"] gets assigned a value it gets the value 55, not 7.
For starter programs, you should possibly
not try to validate your input. If you use
int x;
cin >> x;
your program will assign an integer to x. When you've got a handle on understanding how map<string,int> works, then maybe you can take a look at what happens when you enter 'abcd' instead of a number at your input prompt.