i have this code:
it goes it loops of itself if u input wildcards or charsCode:cout<<"level number:";
cin>>levnum;
how would i stop it doing this ie return an error saying incorrect levnum?:D
Printable View
i have this code:
it goes it loops of itself if u input wildcards or charsCode:cout<<"level number:";
cin>>levnum;
how would i stop it doing this ie return an error saying incorrect levnum?:D
Read a string instead of whatever levnum is now and validate it by checking the length of the string and that each element matches a digit and that the number is within your range for levels, then convert it to an integer with atoi.
-Prelude
After you get the input do this:
#include <ctype.h>
if(isdigit(levelnum))
{
// Is a digit
}
else
{
cout << "Must be digit!";
}