A password-protected security door can only be opened when a user inserts a valid 4-digit personal identification number (PIN).
The program starts by asking the user to enter a 4-digit PIN.If it is valid, the locked door is opened and the program returns for another user input. If, on the other hand, the PIN is invalid the program checks whether three attempts were made. If so, the alarm is triggered; otherwise the user is given another try to input the correct PIN.
Assume that your security door system supports 10 users each with a unique PIN.
....................
i done it with only 1 user (one password) heres the code:
#include <iostream>
using namespace std;
if u are planning for only 10 passwords, have a const array like
constint pins[]={102,1123,1145,234};
store all the pins in it.
ask the user to enter the pin,Traverse through pin array, if the user entered value is found open door.
if u are planning for a practical application a more sophisticated approach will be required which will make use of custom encrypted container to store the pins.
constint pins[]={1,2,3,4,5};
int pincorrect=0;
int userpin=0;
cout<<"Please enter the pin";
cin>>userpin;
//assuming the pins array to be of size 5
for(int i=0;i<5; i++)
{
if(userpin == pins[i])
{
pincorrect=1;
break;
}
}
if(pincorrect == 1)
{
cout<<"open door";
}
else
cout<<"invalid pin, door remains closed";
With this code, you get 3 attempts at guessing the pin. With each failed attempt, "Wrong!" is printed to the screen which then increments the Attempts counter. Otherwise, "Correct!" is printed and the loop ends.
thanks alot man i learned alot from you,
and it works ok,
but there's in the problem he needs it for 10.
Assume that your security door system supports 10 users each with a unique PIN.
that's my problem i know i need array and loop i dont know how to deal with them
i know i'm asking alot but i'll apreciat it if you can write for me so i can learn how to do this kind of problems.
about the heads up yes i know i posted the same in another forum couse i didn't want to bother him he did enough and helped me and learned from him and learned from the other forums thanks all for your time and i see it's being a problem here so i apoligize.
i'm just trying to get the experiance on how to write they gave me useful hints i can work on them.