Answer the question
In order to leave comments, you need to log in
Checking the correctness of the input data, the function does not work correctly! Where is the mistake?
int check_value(int &value)
{
bool check = true;
string temp = "";
do
{
getline(cin, temp, '\n');
for (int i = 0; i < temp.size(); i++)
{
if (temp[i] != '2' && temp[i] != '3' && temp[i] != '4' && temp[i] != '5' && temp[i] != '6'
&& temp[i] != '7' && temp[i] != '8' && temp[i] != '9' && temp[i] != '0' && temp[i] != '1'
&& temp[i] == ' ')
{
cout << "Ошибка! Введите корректное значение:" << endl;
cin.clear();
check = false;
break;
}
else
{
check = true;
}
}
} while (!check);
if (check)
{
value = stoi(temp);
return value;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question