Anyone good at coding in C. i am lost, i need to create a code for a digital lock. the code must allow ten correct 4 digit pins to be entered, but that is the max. the idea is only 10 people can enter a secure room and once 10 are in no one else can get in untill someone leaves.
Hi,
The problem has been resolved. The digital lock has been created successfully. This lock will ask you to input 4 digit pin. Once you input the correct pin this will get you enter. I have set a hard coded pin that is '1234'.Now who will put the pin 1234 will enter the room. this will allow only 10 people to enter. After 10 it will show you that the room is full.
Please find the below screenshot of running code:
Screenshot:


Code:
----------------
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#define MAX_LIMIT 20
bool verifyInput(char str[]){
for (int i=0; i<4; i++)
{
if (isdigit(str[i]) == 0)
return false;
}
return true;
}
bool verifyPin(char str[]){
char pin[]="1234";
str[strlen(str)-1] = '\0';
if (strcmp(str,pin) == 0)
return true;
else
return false;
}
int main () {
char str[MAX_LIMIT];
int maxTry=10;
do {
printf("For login, Please
enter 4 digit pin:\n");
fgets(str, MAX_LIMIT, stdin);
printf("The Input pin is: %s\n", str);
int len = strlen(str);
len--;
printf("Len : %d\n", len);
if(len!=4){
printf("Wrong pin!! You have to enter 4
digit pin\n\n");
}
else{
bool isValid=
verifyInput(str);
printf("isValid: %d\n",
isValid);
if(isValid==1){
bool isVerified
= verifyPin(str);
if(isVerified==1){
printf("Verification Done!! You are
in...\n\n");
maxTry--;
}
else{
printf("Wrong pin!! Try again...\n");
}
}
}
}while( maxTry>0 );
if(maxTry==0){
printf("Room is full\n");
}
return 0;
}
-----------------
The problem has been resolved, I hope you will like the solution. If you have any question or query regarding this problem or other, please comment below and give the positive rating.
Thank You!! Happy Learning!! Keep Chegging!!
Anyone good at coding in C. i am lost, i need to create a code for...
I need help coding this scenario. I am trying to find the ICD-10-PCS code Diagnosis: NSTEMI Thrombectomy of the left circumflex artery. stenting angioplasty of the left circumflex artery. stenting angioplasty of the LAD. stenting angioplasty of the RCA. coronary angioplasty.
I am needing to code a coffee mug in OpenGL using c++. I have
found the coding for a tea kettle but we have been told we cannot
use a tea kettle. I have attached a photo for reference. Thank you
for any help you can provide!
Java Branches code not working please HELP!! I am trying to build this class that will ask for an ingredient, and the number of cups of the ingredient. It should then branch into an if/else branch off to verify that the number entered is valid and that it is within range. Once that branch completes it should then continue on to ask for the calories per cup, and then calculate total calories. Once I get it to enter the branch...
I am confused about how to code this. I have tried multiple ways of coding this and nothing has worked for me. If someone could help that would be great thanks. /*Chess Board: You will also create 5 "lanes" of "pieces" and each lane has that number of pieces on it; i.e. lane 5 = 5 pieces, lane 4 = 4 pieces, etc. The user and the computer can take any number of pieces from one lane. The object is...
I need it in c++ The U.S. Banking System The code assigned to a bank is an eight digit number plus a ninth check digit. To check for validity, the first eight digits are assigned weights (left to right) of 7, 3, and 9 repetitively. Each digit is multiplied by its weight and the products summed. The resulting sum (mod 10) should equal the check digit. The assigning of weights insures that all single digit errors and most transposition errors...
I need help to write this code in C++, I am struggling to find
max node's parent's right child and max node's left child.
Node* maxValueNode(Node* node)
{
Node* current = node;
while (current && current->right !=
NULL)
current = current->right;
return current;
}
void deleteNode(BST* tree, Node* node, Node* parent)
{
//TODO - follow the lecture pseudocode to write the
deleteNode function
// - returns true if the value was deleted, false if
not
// - don't forget to...
I need help coding a button to do the following in C#. You can use your choice of variable names, etc... Displays the multiplication table for the start number (allow only 1-12) entered by the user. For example, if the user entered 5, the following would display in the output control. Ignore entry of the end number. 1 * 5 = 5 2 * 5 = 10 3 * 5 = 15 4 * 5 = 20 5 * 5...
Can someone help with this C++ code. I am trying to compile and I keep running into these 4 errors. #include <iostream> #include <cassert> #include <string> using namespace std; typedef int fsm_state; typedef char fsm_input; bool is_final_state(fsm_state state) { return (state == 3) ? true : false; } fsm_state get_start_state(void) { return 0; } fsm_state move(fsm_state state, fsm_input input) { // our alphabet includes only 'a' and 'b' if (input != 'a' && input != 'b') assert(0); switch (state) {...
Can someone help me fix my C code. I am getting segmentation fault along with missing termination " /* These are the included libraries. */ #include #include #include #include void printTriangle(char *str); int main() { char sentence[81]; int done = 0; while(done != 1) { printf("Please enter the sentence or quit: "); fgets(sentence, 80, stdin); if(strcmp(sentence, "quit") == 0) done = 1; else printTriangle(sentence); } } void printTriangle(char *str) { int index = 0; int line = 1; int i;...