Learning C language for one weeks, the teacher assigned to work, using C to write an ATM simulation program, customer interface has, withdrawals, 2 deposits, 3 transfers, 4 exit.
And after the input error is required, there are three chances to re-lose, define the input password hellowold, with Switch branch.
#include <stdio.h>#include<string.h>#defineKey "Hellowold"//Define Password#defineZhanghu "123456789"#defineLine "==================\n"intNum//Select TypeChararr[ -];//Defining ArraysCharpassword[ -];//Defining ArraysintMoney//Withdrawal AmountintI=0;intMain () {printf (line); printf ("\t1 withdrawals \ n"); printf ("\t2 deposit \ n"); printf ("\t3 transfer \ n"); printf ("\t4 exit \ n"); printf (line); printf ("Please select the type of operation: \ n"); scanf ("%d",&num); Switch(num) { Case 1: { Do{printf ("Please enter your password: \ n"); scanf ("%s",&password); if(strcmp (key,password) = =0) {printf ("Please enter the withdrawal amount: \ n"); scanf ("%d",&Money ); printf ("Please take your%d grandpa's hair.", Money); Break; } Else{printf ("Password input Error"); } I++; } while((strcmp (key,password)! =0) &&i<=2); } }
Second step deposit, define Account
#include <stdio.h>#include<string.h>#defineKey "Hellowold"//Define Password#defineZhanghu "#defineOther "ni de mao ye Ye"#defineLine "==================\n"intNum//Select TypeChararr[ -];//Defining ArraysCharpassword[ -];//Defining ArraysCharothers[ -];intMoney//Withdrawal Amountintnum2;//Deposit AmountintI=0;intMain () {printf (line); printf ("\t1 withdrawals \ n"); printf ("\t2 deposit \ n"); printf ("\t3 transfer \ n"); printf ("\t4 exit \ n"); printf (line); printf ("Please select the type of operation: \ n"); scanf ("%d",&num); Switch(num) { Case 1: { Do{printf ("Please enter your password: \ n"); scanf ("%s",&password); if(strcmp (key,password) = =0) {printf ("Please enter the withdrawal amount: \ n"); scanf ("%d",&Money ); printf ("Please take your%d grandpa's hair.", Money); Break; } Else{printf ("Password input Error"); } I++; } while((strcmp (key,password)! =0) &&i<=2); Break; }
Today first change to here, the homework is more, typesetting is not very good-looking, it will look at it.
A program of ATM machines written in C language