Please can anyone help,I need to write a code using C for a phone lock password that makes you try three times and in the 4 stop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please can anyone help,I need to write a code using C for a phone lock password that makes you try three times and in the 4 stop

6th Jan 2023, 6:15 PM
Shahd Omer
11 Answers
0
Here are a few YouTube channels that might be helpful for learning C: Learn C Programming - This channel offers a variety of tutorials on C programming, ranging from beginner to advanced topics. MyCodingZone - This channel has a series of tutorials on C programming, as well as other programming languages. Programming with Mosh - This channel has a number of tutorials on C programming, as well as other programming languages. Coding Road - This channel has a number of C programming tutorials, as well as tutorials on other programming languages. LearnCode.academy - This channel has a number of tutorials on C programming, as well as other programming languages. I hope these channels are helpful for your learning journey! Let me know if you have any other questions.
6th Jan 2023, 6:44 PM
Aditya Dixit
+ 5
#include <stdio.h> #include <string.h> int main () { char password[10] ; int num_of_tries = 1; while ( num_of_tries <= 3 ) { printf("Enter Password: "); scanf("%s" , &password); if (strcmp( password , "password" ) == 0) { printf("Correct Password, Login Successful\n"); return 0; } else { printf("Incorrect Password, Login Unsuccessful\n"); } num_of_tries++; } printf("\nMaximum Attempts Reached !\n"); return 0; }
7th Jan 2023, 7:20 AM
Cool-Coder
Cool-Coder - avatar
+ 1
Thank you very very very very much
6th Jan 2023, 6:50 PM
Shahd Omer
0
You need to learn basics of loops and conditionals statements
6th Jan 2023, 6:28 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
For statement and if condition?
6th Jan 2023, 6:33 PM
Shahd Omer
0
I know them but I'm a beginner I don't know what to do
6th Jan 2023, 6:34 PM
Shahd Omer
0
First you have to learn basics refer any YouTube tutorial
6th Jan 2023, 6:36 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Well, i can provide you basic example for this : #include <stdio.h> #include <string.h> #define MAX_ATTEMPTS 3 int main() { char password[20]; int attempts = 0; printf("Enter password: "); scanf("%s", password); while (strcmp(password, "123456") != 0 && attempts < MAX_ATTEMPTS) { printf("Incorrect password. Try again: "); scanf("%s", password); attempts++; } if (attempts == MAX_ATTEMPTS) { printf("Maximum attempts reached. Phone lock activated.\n"); } else { printf("Correct password. Phone unlocked.\n"); } return 0; }
6th Jan 2023, 6:36 PM
Aditya Dixit
0
This code prompts the user to enter a password and compares it to the correct password, which is "123456" in this example. If the password is incorrect, the user is prompted to try again up to three times. If the password is correct or the maximum number of attempts has been reached, the program displays a message indicating the current state of the phone lock.
6th Jan 2023, 6:37 PM
Aditya Dixit
0
Thank you very much!! Can you recommend a good YouTube channel that may helps?
6th Jan 2023, 6:40 PM
Shahd Omer
0
Like my answer if you happy
6th Jan 2023, 6:45 PM
Aditya Dixit