Little Game Project - cin numeric only

#1

Hi,

As part of the course we do the little game project in c++. I’m a new c++ guy, so this is trial an error for me:

I’ve tried to extend the exercise and make sure player 1 and 2 only can type numbers. This works fine by using the code at the end of the message. What I can’t wrap my head around is:

If player one types 5 and player two types 5½ it says “YOU GUESSED IT”. How can it make that a too high guess?

Here is the code for making sure they type a number:

#include

do{
cout << “Player one please type a random number” << endl;
cin >> numberTyping;

    bFail = cin.fail();
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    if(bFail== true){cout << "This is not a valid input. Try again!" << endl;}

} while (bFail == true);
0 Likes