C language: simulate a program that automatically withdraws money by entering a password
Simulate a program to automatically withdraw money by entering a password:
# Include <stdio. h> # include <windows. h> # include <string. h> int main () {char * p = "123456"; char passwd [10]; int I = 0; for (I = 0; I <3; I ++) {printf ("enter the password (up to 9 digits):"); scanf ("% s", passwd); if (strcmp (p, passwd) = 0) // if the password is the same as 0, the password is correct {break;} else {printf ("Incorrect password! \ N ") ;}}if (I = 3) {printf (" three times wrong password input, turn off the system after 5 seconds \ n "); Sleep (5000 );} else if (I <3) {printf ("money Acquisition successful \ n") ;}return 0 ;}
Result 1: Enter the password (up to 9 digits): 1237689 the password is incorrect! Enter a password (up to 9 digits): 943209 incorrect password! Please enter the password (up to 9 digits): 123456 to get the money, please press any key to continue... result 2: Please enter the password (up to 9 digits): 132147 wrong password entered! Enter a password (up to 9 digits): 98574 incorrect password! Enter a password (up to 9 digits): 07534 incorrect password! The password entered three times is incorrect. Shut down the system in 5 seconds and press any key to continue...