+ 1
Could someone show me how to provide validation of input in C++?
Like if you write a program to accept a 10 digit account number as input, if the user enters 9 or lesser digits, or an alphabet, it gives an error...
3 Antworten
+ 4
Following block is Not exactly what you want but give you the idea.
int num = 0;
int n = 1;
do{
std::cout << "Enter number #" << n << " : ";
std::cin >> num;
if (std::cin.fail())
{
std::cin.clear();
std::cin.ignore(200, '\n');
std::cout << "Invalid input!\n";
continue;
}
++n;
} while (n<=10);
+ 1
Thank you all...
0
in c# I would count the variable and equate to 10, for alphabets I would use a function isinteger to ensure he/she entered numbers. example string numb = input
numb.Count ==10;
just look at a function on isinteger if it exists and how to use it.