'n' is a char type, whereas X is an int type. This causes std::cin to fail, and because you never check for cin.fail(), your program continuously loops. If this was an assignment, I'm pretty sure that n was meant to be a numeric constant (like -1 or 0) of your choice.