jeudi 22 août 2019

I ask for a number in this code, what should I do in case the user gives a letter instead?

The problem is what should I do to prevent the user to put a char instead of a number in floats h,a,b,A or B

I've tried using typeid, but I don't know how that works

int main() {
  float h, a, b, A, B;
  std::cout << "Llena los datos, si no tienes algún dato, escribe 0\n";
  std::cout<<"Hipotenusa:";
  std::cin >> h;
  std::cout<<"Lado a: ";
  std::cin>> a;
  std::cout<<"Lado b: ";
  std::cin>> b;
  std::cout<<"Angulo A: ";
  std::cin>> A;
  std::cout<<"Angulo B: ";
  std::cin>> B;
}

If the user gives a char value for one of the variables, I expect an output of "Incorrect Value", which is "Datos Incorrectos" in spanish.

Aucun commentaire:

Enregistrer un commentaire