Answer to Question #331044 in C for nas17

Question #331044

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


1
Expert's answer
2022-04-19T15:27:58-0400







#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS