@
@
@ackeeee2020-10-30 03:48:01
C++ / C#
@ackeeee, 2020-10-30 03:48:01

How to validate input data in c++?

I have code that takes three int outputs from keyboard input. I need to display an error if the user entered a non-numeric value. The error needs to be specified. How is it possible to implement it?

#include <iostream>
using namespace std;

int main()
{
double a_number, b_number, result;
    int c_number;

    cout <<"Введите вещественное число а в диапазоне от -1000.0 до 1000.0 включительно: \n";
    cin >> a_number;
    cout <<"Введите вещественное число b в диапазоне от -1000.0 до 1000.0 включительно: \n";
    cin >> b_number;
    cout <<"Введите вещественное число c в диапазоне от -1000.0 до 1000.0 включительно: \n";
    cin >> c_number;
    {
        result = sqrt(a_number-b_number)/ (c_number%2);
        cout << result;
    }

    return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
poniyur, 2020-10-30
@ponyyur

https://ravesli.com/urok-72-obrabotka-nekorrektnog...

A
Alexander Ananiev, 2020-10-30
@SaNNy32

https://en.cppreference.com/w/cpp/locale/isdigit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question