Check out example codes for "how to ensure the user inouts a int and not anything else c++". It will help you in understanding the concepts better.

Code Example 1

int x;
    std::cin >> x;
    while(std::cin.fail()) {
        std::cout << "Error" << std::endl;
        std::cin.clear();
        std::cin.ignore(256,'\n');
        std::cin >> x;
    }

Learn ReactJs, React Native from akashmittal.com