I'm writing a program and I'm stuck on one part.
First I ask a user to enter a PIN, and if the PIN is 4 numbers long it passes to the next step.
If it is not 4 numbers long the user is given 3 chances to re-enter the correct PIN (just has to be 4 numbers long).
If after 3 chances the user does not enter the correct PIN, the program ends.
So far I managed to get this:
printf("Enter PIN: ");
scanf("%d", %26amp;PIN);
while (PIN != 0)
{
count++;
PIN /= 10;
}
if(count != 4)
{
printf("Invalid PIN, Re-enter Pin: ");
scanf("%d", %26amp;PIN);
}
I'm not sure how to make this into one loop so that if an incorrect PIN is entered, you have three chances to get it right.
Please help me in any way possible.
Thanks
C programming loop help?
I would suggest wrapping this whole thing in a for loop, like
for (i=1; i%26lt;=3; i++)
and when you check for valid pin, if count==4, then break;
You'll need to initialize count at the top of the loop.
Also, if you're required to print something after entering the correct PIN, you could do that either when checking for count==4, or after the for loop, check count again.
If you have to account for people putting in things like "abc1234", then your scanf() will need a little work.
Great job, thanks for posting partial code, instead of just asking people to write it for you.
Reply:i forget syntex of c but hope u will correct it i try one code like follow may be it will help u.
printf("Enter PIN: ");
scanf("%d", %26amp;PIN);
test=0;
function void p1()
{
printf("Enter PIN: ");
scanf("%d", %26amp;PIN);
}
while (PIN != 0)
{
count++;
PIN /= 10;
}
if(count %26lt; 4)
{
if(test%26lt;3)
{
p1();
test++;
}
}
else
{
your second step;
}
i here i want to tell make method for your code and use it in programe.
parts of a flower
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment