+ 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
11 Respuestas
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.
+ 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;
}
+ 1
Thank you very very very very much
0
You need to learn basics of loops and conditionals statements
0
For statement and if condition?
0
I know them but I'm a beginner I don't know what to do
0
First you have to learn basics refer any YouTube tutorial
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;
}
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.
0
Thank you very much!!
Can you recommend a good YouTube channel that may helps?
0
Like my answer if you happy