The problem is caused by the non type safeness of scanf(). You pass the address of a unsigned short, but it expects an int. Since sizeof(int) > sizeof(unsignedshort), scanf will try to access memory, it doesn't own.
For formatted input, use std::istream and it's realitves. You can read about them in the tutorial on this site.