Write a program which takes PIN number of the user as input and then verifies his pin. If pin is verified the program shall display “pin verified” and “Welcome”; otherwise, the program shall give user another chance. After 4 wrong attempts, the program shall display “Limit expired” and then exit. Use for loops to implement the logic.
Note: 5 random PIN numbers can be assumed and fed into the program with which input pin is matched
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define bool int
//Program PIN
//Implement function to generate random PIN - 5 len
void genPin(unsigned pin[5])
{
for(unsigned i=0;i<5;i++)
pin[i]=rand()%10;//Dont forget Digit [0..9]
}
//Implement choose the cur pin
bool isEqual(unsigned cr[5],unsigned pin[5])
{
for(unsigned i=0;i<5;i++)
if(cr[i]!=pin[i])
return 0;
return 1;
}
//Put pin
void EnterPIN(unsigned p[5])
{
for(unsigned u=0;u<5;u++)
{
char cur;
scanf("%c",&cur);
p[u]=cur-'0';
scanf("\n");
}
}
//WritePass
void WritePass(unsigned p[5])
{
for(unsigned u=0;u<5;u++)
printf("%u",p[u]);
printf("\n");
}
int main(void) {
unsigned pin[5];
unsigned cr[5];
unsigned i=4;
genPin(pin);
while(i--)
{
EnterPIN(cr);
if(isEqual(cr,pin)==1)
{
printf("Pin verified\nWelcome\n");
return printf("");
}
}
printf("Limit expired\n");
printf("\n");
printf("PIN was..=");
WritePass(pin);
return 0;
}
Comments
Leave a comment