To receive from shell an integer value comprised within the (0, 8) interval, I cin
to an uint8_t
element of an array, doing the following:
char answer;
do
{
// Instructions
std::cout << "Linear actuator resolution is:\n"
<< "\u0394x = \u03B1r/2^i, with \u03B1 = " << std::to_string(ALPHA)
<< " degrees, r = " << std::to_string(pulleyR) << " m and i in [0 : 8]\n";
// Parameter selection
std::cout << "Please enter a valid value for param 'i': ";
std::cin >> Engines_uSteppingLevel[RAIL];
if(Engines_uSteppingLevel[RAIL] > (RES_LEVELS - 1))
// Wrong selection, repeat question
std::cout << '\r';
else
{
// Print out the selected resolution and ask user to confirm or restart selection
std::cout << "Selected linear resolution: " << std::fixed << std::setprecision(4)
<< ALPHA*pulleyR/(1<<Engines_uSteppingLevel[RAIL])
<< "m, enter 'y' to confirm, any other key to change selection ";
std::cin >> answer;
if(answer == 'y')
break;
}
}while(true);
Even though I enter a correct value, the loop does not break.
Entering:
std::cout << Engines_uSteppingLevel[RAIL] << ' ' << (RES_LEVELS - 1) << '\n';
in place of:
std::cout << '\r';
shell output is:
Please enter a valid value for param 'i': 0
0 8
Please enter a valid value for param 'i': 3
3 8
which does not make sense.