How can i make it so that my input only allows either the char a or b.

Basically this is what i have now.

                cout << "Enter either a or b: ";
                char ab;
                cin >> ab;

                cout << ab;

But in the event someone enters something other than a or b how can i make it keep asking until they do?

I got it! I ended up doing a switch case in a do while loop

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.