用c語言編寫的一個ATM取款機程序


學了一個多星期的c語言了,老師布置來了作業,用C編寫個ATM機的模擬程序,客戶界面有,取款,2存款,3轉賬,4退出。

並且要求輸入錯誤后,有三次機會重輸,定義輸入密碼hellowold,用switch分支。

 

#include<stdio.h>
#include<string.h>
#define key "hellowold"//定義密碼 
#define zhanghu "123456789"
#define line "==================\n"
int num;//選擇類型 
char arr[20];//定義數組 
char password[20];//定義數組
int money;//取款金額 
int i=0;
int main()
      {
        printf(line);
        printf("\t1取款\n");
        printf("\t2存款\n");
        printf("\t3轉賬\n");
        printf("\t4退出\n");
        printf(line);
        printf("請選擇操作類型: \n");
        scanf("%d",&num);
        switch(num)
        {
            case 1:
            {   do
                 {  
                     printf("請輸入密碼:\n");
                    scanf("%s",&password);
                    if(strcmp(key,password)==0)
                    {
                        printf("請輸入取款金額:\n");
                        scanf("%d",&money); 
                        printf("請取走你的%d毛爺爺",money);
                        break;
                    }
                    else
                    {
                        printf("密碼輸入錯誤"); 
                    }
                    i++;
                   }
                   while((strcmp(key,password)!=0)&&i<=2);
                
            }
        } 

第二步 存款,定義賬號

 

#include<stdio.h>
#include<string.h>
#define key "hellowold"//定義密碼 
#define zhanghu "
#define other "ni de mao ye ye"
#define line "==================\n"
int num;//選擇類型 
char arr[20];//定義數組 
char password[20];//定義數組
char others[20];
int money;//取款金額 
int num2;//存款金額 
int i=0;
int main()
      {
        printf(line);
        printf("\t1取款\n");
        printf("\t2存款\n");
        printf("\t3轉賬\n");
        printf("\t4退出\n");
        printf(line);
        printf("請選擇操作類型: \n");
        scanf("%d",&num);
        switch(num)
        {
            case 1:
            {   do
                 {  
                     printf("請輸入密碼:\n");
                    scanf("%s",&password);
                    if(strcmp(key,password)==0)
                    {
                        printf("請輸入取款金額:\n");
                        scanf("%d",&money); 
                        printf("請取走你的%d毛爺爺",money);
                        break;
                    }
                    else
                    {
                        printf("密碼輸入錯誤"); 
                    }
                    i++;
                   }
                   while((strcmp(key,password)!=0)&&i<=2);
                   break;
                
            }

        

今天先變到這里吧,作業還多着了,排版不是很好看,就將就這看吧。

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM