c语言银行自动取款系统,[c语言]模拟银行atm机,实现存款、取款等业务

可以使用结构体来存储账号、密码、余额等。

//

// main.c

// testATM

//

// Created by 赵亚北 on 14-7-10.

// Copyright (c) 2014年 zyb. All rights reserved.

//

#include

#include //结构体

typedef struct card{

int cardNumber;

int cardPassword;

float money;

bool state;

}Card;

int cardManage(Card card[],int cardCount){//验证卡号

while (1) {

int cardN=0;

printf("input you cardNumber\n");

scanf("%d",&cardN);

for (int i=0; i

if (cardN==card[i].cardNumber&&card[i].state==1) {

return i;

}

else if (cardN==card[i].cardNumber&&card[i].state==0){

printf("you card was locked ,please go our company for help \n");

return -1;

}

}//for

printf("card number rong\n");

}//while

}

bool pw(Card card[],int i){//验证密码

int pw;

int times=3;

while (times--) {

printf("input your password:");

scanf("%d",&pw);

if (pw==card[i].cardPassword) {

printf("password right \n");

return 1;

}

else printf("password is not right! you have %d times to input\n",times);

}

card[i].state=0;

printf("card locked! ");

return 0;

}

void service(Card card[],int i){//账号密码均正确后提供服务

while (1) {

printf("1 取款 \n2 存款\n3 查询\n4 退出\n");

static int order;

scanf("%d",&order);

switch (order) {

case 1:

printf("input money counts less then 2000:");

static int money=0;

scanf("%d",&money);

if (money>2000) {

printf("less then 2000\n");

}

else if (money>card[i].money)printf("money not enough\n");

else {

card[i].money-=money;

printf("you have %f\n",card[i].money);break;

}

break;

case 2:{

printf("input money:");

int money=0;

scanf("%d",&money);

card[i].money+=money;

printf("all right,remain money %g\n",card[i].money);

}

break;

case 3:printf("remain money %g\n",card[i].money);

break;

case 4:

return;

default:

break;

}//switch

}//while

}

int main(int argc, const char * argv[])

{

Card card[4]={{123,222,1000,1},

{255,221,50000,1},

{124,255,50,1},

{125,999,900,1}};

int num=0;

while (1) {

num=cardManage(card, 4);

if (num<0) {

continue;

}

bool result=0;

result=pw(card, num);

if (result==0) {

continue;

}

service(card, num);

}

return 0;

}

运行截图:

0818b9ca8b590ca3270a3433284dd417.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值