im wondering how I can ask the user to input a 4 digit pin and it can only be 4 numbers and if its not 4 numbers it it will give them an error and let them retype the pin but im stuck on how to do it any help would be appreaciated
this as well is in a function which is called void welcomeMessage()
1 2 3 4 5 6 7 8 9 10 11
int pin=0;
if (pin==1234)
{
cout<<"Please enter a 4 digit pin: ";
cin>>pin;
}
elseif(pin<1234||pin>1234)
{
cout<<"NOT the correct pin"<<endl;
}
ok cool thanks and one more question if they enter the wrong pin how can I make it so they have to enter the pin again and wont let the program run until they put the correct pin??
the only problem Is if they enter more than 4 numbers or less it will give the invalid pin message but it will continue to run the program and I don't want it to run until they enter the right pin.
this is what I have
how could I display and error message saying it wasn't the correct pin?? cause if I were to enter invalid pin after the cin>>r; it runs but after it displays invalid pin how could I fix that??
It's pretty simple. You want a loop that runs until a pin in correctly input. EssGeEich showed yo usomething like this with no error message. If you want the error message you could do this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int pin = 0;
//get the pin for the first time.
cout<<"Enter your 4 digit pin please: ";
cin>>pin;
//if the pin is smaller then 1000 (3 digits or less) or greater then 9999 (5 digits or more) have the user re input their pin and give an error
while (pin<1000 && pin>9999)
{
cout << "ERROR: Invalid Pin: " << endl;
cout<<"Enter your 4 digit pin please: ";
cin>>pin;
}
//continue on with code to check the pin etc.