I need help with this problem can you solve it for me ( write the program)

-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.

and i'll BE THANKFULL,

it's not homework,

i have a final exam and this question was in one of the final exam sample
i just want to know how to solve it.

hope you can help.

it's not homework

It's close enough.

i have a final exam and this question was in one of the final exam sample
i just want to know how to solve it.

I have an idea, how about you try to solve it and we'll help out when you hit any stumbling blocks. Just having someone else solve the problem for you doesn't teach you jack about how to solve problems.

thank you for your replay :))

the problem want 10 supports user i only done one couse i dont know how to do it for ten and here is what i done

#include <iostream>

void main()
{
int pin=1234;
int pin2=0;
int cont=0;

while(cont<3)
{
if (pin2==0)
{
std::cout << "please enter your pin number\n" ;
std::cin >> pin2;
}
if ( pin==pin2)
{
std::cout << "Door opens\n" ;
cont=4;

}
else
{
cont++;
pin2=0;
}
if (cont==3)
{ std::cout << "Alarm\n" ;
}
}
}

i'm a begienner in programming and i tried my best so please help me.

First, as a minor point that you should be aware of, you should never use void as the return type of the main() function. While earlier versions of the C standard allowed it, it is non-portable; in C++, it is strictly forbidden. Use int main() in the future, please.

Also, please make sure your code is suitably indented to make reading easier. While the formatting conventions may make the code look like some sort of weird poetry, they make the code far easier to read, and with practice become quite natural.

As for how you would allow for multiple users' PINs, the answer lies with arrays, and a loop on the test for whether the PIN matches or not. If you have covered arrays at all yet, this should become clear with a little thought.

I would add that it would make far more sense to use a 4-character array for the PIN, and a test to make sure that the input is numeric (using the function isdigit() from the <cctype> library). The reason for this should become apparent if you consider the case of PINs starting with a zero ('0') character.

thanks man very much,
I'm here to learn first. i really learned alot from you now, i understand the arrays and loops
i know what they do but my problem is writing the program i'm good at the theory part but at tutorial that my difficulty.

I will apreciat it if you can write me the progrom or a program similar to it so i can see how it's written.

thanks again man BIG TIME.

That, unfortunately, is one thing we won't do for you here; you have to write the program on your own, we'll help you debug it but we won't write it for you

thanks man i think i got it will write and post it here to show you is it right or wrong

This article has been dead for over six months. Start a new discussion instead.