Im trying to do this: if the value is greater than 50 or less than -50, or not an integer, than cin again the value (until it is valid)
for (size_t i = 0; i < cities; i++)
{
for (size_t j = 0; j < days; j++)
{
cout << "temperature(" << i + 1 << ',' << j + 1 << ") = ";
cin >> *(temperatures + i * days + j);
while (!(*(temperatures + i * days + j) > 50 && *(temperatures + i * days + j) < -50))
{
cin.clear();
cin.ignore();
cout << "temperature(" << i + 1 << ',' << j + 1 << ") = ";
cin >> *(temperatures + i * days + j);
}
}
if i write a number greater than 50, or less than -50 it works.
But if i write eg.:
temperature(1,1) = covid
than the next row:
temperature(1,1) = temperature(1,1) = temperature(1,1) = temperature(1,1) = temperature(1,1) =
How can i fix this?
get_int, a robust function that inputs an integer fromstd::cin.get_inthandles all the usual errors that can happen withstd::cin, and loops until a valid integer is entered.