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?
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?
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
My best code is written with the delete key.
After you get the input do this:
#include <ctype.h>
if(isdigit(levelnum))
{
// Is a digit
}
else
{
cout << "Must be digit!";
}
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK