EnergyState::On should be equal to 0 and off equal to 1. I would change state = static_cast<EnergyState>(s); to state = s or just simply remove the state part then at the end put ((s == EnergyState::ON) ? "on" : "off")
Sorry it should just be static_cast<EnergyState>(s-'0'); didn't realize you are using unsigned char instead of int.
The problem was the use of unsigned char? I don't understand why there is a difference using unsignedshortint for instance. Both unsignedchar and unsignedshortint are integral types.
The following seems to work just fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
enumclass EnergyState : unsignedshortint {
ON,
SUSPENDED,
OFF
};
int main()
{
EnergyState state;
unsignedshortint s;
std::cin >> s;
state = static_cast<EnergyState>(s);
std::cout << "Your computer is currently "
<< ((state == EnergyState::ON) ? "on" : (state == EnergyState::SUSPENDED) ? "suspended" : "off")
<< "." << std::endl;
return 0;
}