efrei/programmation-c-cpp/tp2/code-pin.c

36 lines
619 B
C
Raw Normal View History

2021-10-18 10:47:24 +02:00
/* Code PIN */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CODE "1928"
int verifier_code(char*);
int main() {
char pin[4];
for (int i = 0; i < 3; i++) {
printf("Code PIN : ");
scanf("%s", &pin);
if (verifier_code(pin)) {
break;
} else {
printf("Il reste %d tentatives\n", 2 - i);
}
}
return 0;
}
int verifier_code(char* pin) {
if (strcmp(pin, CODE) == 0) {
printf("Téléphone dévérouillé\n");
return 1;
} else {
printf("Erreur, mauvais code\n");
return 0;
}
}