C语言:简单的ATM.

注:转账判断账号那一步还有瑕疵。

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>
int choice, i, j, r, transNum, enterID, enterPW, remitID, userRemit;
int userInfo[100][2] = {{12, 123}, {13, 123}};
double userCurrent[100] = {1000.00,1500.00};
double userInput, userOutput;
void pwJudge();
int menu();
int current();
int input();
int output();
int remit();
//主函数main/ 
int main(void) {
	int choice = -1;
	while (1) {
		printf("\t\t\t欢迎使用XX银行ATM机\n");
		printf("\t1.登录\n");   ///pwJudge
		printf("\t2.退出\n");   ///exit退出程序 
		scanf("%d", &choice);
		switch (choice) {
			case 1:
				system("cls");
				pwJudge();
				break;		
			case 2:
				system("cls");		
				exit(0);
				break;
			default:
			 	system("cls");
				printf("\t\t\t输入有误,请重新输入\n");
				Sleep(3000);
			 	break;
		}
	}	
} 
/进入主菜单menu///
int menu() {
	int choice = -1;
	while (1) {
		printf("\t\t\t迎使用XX银行ATM机\n");
		printf("\n");
		printf("\t\t\t请选择服务类型\n");
		printf("1.查询\n"); //current
		printf("2.存款\n"); //input
		printf("3.汇款\n"); //remit
		printf("4.取款\n"); //output
		printf("5.切换账号\n");
		printf("5.退出\n");//exit退出程序 
		scanf("%d",&choice);
		switch (choice) {
			case 1 :
		 		system("cls");
				current();
				break;
			case 2 :
				system("cls");
				input();
				break;
			case 3 :
				system("cls");
				remit();
				break;	
			case 4 :
				system("cls");
				output();
				break;
			case 5 :
				system("cls");
				return 0;
				break;
			case 6 :
				system("cls");
				exit(0);
			default:
				system("cls");
				printf("输入有误!请重新输入");
				Sleep(1000);
				system("cls");
				break;
		}
	}
}  
密码判断pwJudge
void pwJudge() {
	if (r > 2) {
		system("cls");
		printf("\t\t\t账号或密码已错3次,正在退出\n");
		Sleep(2000);
		exit(0);
		}
	for (j = 0; 1; j++) {
		printf("\t\t\t请输入账号:");
		scanf("%d", &enterID);
		printf("\t\t\t请输入密码:");
		scanf("%d", &enterPW);
		for (i = 0; i <= 10; i++) {
			if ((userInfo[i][0] == enterID) && (userInfo [i][1] == enterPW)) {
				system("cls");
				menu();
				Sleep(1000);
			}
		}
		r++;
	}
}
查询userCurrent
int current() {
	printf("\t\t\t您的余额为:%.2lf", userCurrent[i]);
	Sleep(2000);
	system("cls");
}
//存钱input
int input() {
	printf("请输入您要存入的金额:");
	scanf("%lf", &userInput);
	printf("您的当前金额为:%.2lf", (userCurrent[i] += userInput));
	Sleep(3000);
	system("cls"); 
} 
//取钱output
int output() {
	printf("请输入您要取出的金额:");
	scanf("%lf", &userInput);
	printf("您的当前金额为:%.2lf", (userCurrent[i] -= userInput));
	Sleep(3000);
	system("cls"); 
} 
/汇款remit///
int remit() {
	printf("您的当前余额为%.2lf\n", userCurrent[i]);
	printf("请输入要汇款的账户名:"); 
	scanf("%d", &remitID);
	for (transNum = 0; transNum < 100; transNum++) {
		if (remitID == userInfo[transNum][0]) {	
			break;
		}
	}
		printf("请输入汇款金额(小于当前余额):");
		scanf("%d", &userRemit); 
		userCurrent[i] -= userRemit;
		userCurrent[transNum] += userRemit;
		printf("您的当前余额为%.2f\n", userCurrent[i]);
		Sleep(3000);
		system("cls");
}


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值