简易ATM机程序(c语言版)

详细代码:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <windows.h>

char ch[7] = { "123456" };
void menu();


/* int login(); */
int deposit();


int GetCash();


int Transf();


void Checkmoney();


int checkPass();


void modiPass();


void Exit();


int i, n;
/* 金额 */

int main()
{
	int x;
/* modiPass(); */
	while ( 1 )
	{
		checkPass();
		menu();
		while ( 1 )
		{
			printf( "\n请选择业务:" );
			while ( 1 )
			{
				scanf( "%d", &x );
				if ( x > 6 || x < 0 )

				{
					printf( "\n输入有误,请重新输入:" );
				}else break;
			}
			switch ( x )
			{
			case 1: deposit();
				break;
			case 2: GetCash();
				break;
			case 3: Transf();
				break;
			case 4: Checkmoney();
				break;
			case 5: modiPass();
				break;

			case 6: Exit();
				x = 6;
				break;
			default: break;
			}
			if ( x == 6 )
				break;
		}
	}
	return(0);
}


/* ///菜单 */
void menu()
{
	system( "cls" );
	printf( "\t\t  Please Select Service\n\n" );
	printf( "\n\n\t\t\t**电子现金**\n\n" );
	printf( "\t\t1.存款业务      2.取款业务\n\n" );
	printf( "\t\t3.转账业务      4.查询业务\n\n" );
	printf( "\t\t5.修改密码      6.退卡\n\n" );
}


/* //存款业务 */
int deposit()
{
	int m;
	printf( "请输入您的存入金额\n" );
	scanf( "%d", &m );
	printf( "成功存入 %d 元\n", m );
	i += m;
	return(i);
}


/* //取款业务 */
int GetCash()
{
	int n;
	if ( i <= 0 )
	{
		printf( "余额不足\n" );
		return(i);
	}
	printf( "请输入您的取出金额\n" );
	while ( 1 )
	{
		scanf( "%d", &n );
		if ( n > i )
		{
			printf( "请输入少于%d 元\n", i );
		}else
			break;
	}
	printf( "成功取出 %d 元\n", n );
	i -= n;
	return(i);
}


int Transf()
{
	int		n;
	long int	number;
	if ( i <= 0 )
	{
		printf( "余额不足\n" );
		return(i);
	}
	printf( "请输入您要转帐的银行卡号\n" );
	scanf( "%ld", &number );
	printf( "请输入您的转出金额\n" );
	while ( 1 )
	{
		scanf( "%d", &n );
		if ( n > i )
		{
			printf( "请输入少于%d 元\n", i );
		}else
			break;
	}
	printf( "成功向%ld 账号转账 %d 元\n", number, n );
	i -= n;
	return(i);
}


void Checkmoney()
{
	if ( i <= 0 )
		printf( "您的账户余额: 0 元\n" );
	else
		printf( "您的账户余额: %d 元\n", i );
}

//打印密码,用于调试 
int dump_pwd( char *name, char* a, int b )
{
	int i = 0;
	printf( "===========*****begin*****===========\n" );
	for ( i = 0; i < b; i++ )
		printf( "name is %s,a[%d] is:%c\n", name, i, a[i] );
	printf( "===========*****end*****===========\n" );
}


int checkPass()
{
	system( "cls" );
	char m[7];
	printf( "\n@@@@@@@@中国建设银行@@@@@@@@\n" );
	printf( "\n**China Construction Bank**\n\n" );
	printf( "\n正在进行IC卡认证,请稍吿...\n\n" );
	printf( "请输入密码(系统默认初始密码:123456):\n" );
	printf( "Please input your Press Enter\n\n" );
	/* dump_pwd("mypwd",m,7); */
	while ( 1 )
	{
		for ( n = 0; n < 6; n++ )
		{
			m[n] = getch();
			printf( "*" );
		}
		//dump_pwd( "mypwd", m, 7 );
		//dump_pwd( "moren", ch, 7 );
		if ( strncmp( ch, m, 6 ) == 0 )
		{
			printf( "\n\n\t\t    正在进行ID认证,请稍等" );
/* Sleep(400); */
			printf( "." );
			Sleep( 400 );
			printf( "." );
			Sleep( 400 );
			printf( "." );
			Sleep( 400 );
			printf( "." );
/* Sleep(2000); */
			printf( "\n\n\t\t     登录成功.....\n" );
			break;
		}
		puts( "\n密码错误,请重新输入密码:\n" );
	}
	return(0);
}


void modiPass()
{
	char mi[7];
	printf( "请输入原来的密码:\n" );
	while ( 1 )
	{
		for ( n = 0; n < 6; n++ )
		{
			mi[n] = getch();
			printf( "*" );
		}
		printf( "\n" );
		if ( strncmp( mi, ch, 6 ) == 0 )
		{
			puts( "请输入新的密码:\n" );
			for ( n = 0; n < 6; n++ )
			{
				ch[n] = getch();
				printf( "*" );
			}
			printf( "\n" );
			if ( strcmp( mi, ch ) != 0 )
			{
				printf( "密码修改成功!\n" );
				break;
			}else
				printf( "密码修改失败(新密码与旧密码相同),请重新修改.\n请输入原来的密码:\n" );
		}else
			printf( "密码错误,请重新输入:\n" );
	}
}


void Exit()
{
	printf( "交易结束,请取回您的卡\n" );
	Sleep( 1000 );
}

 

注意:

这里可能涉及到将代码编码为utf-8转换成gbk格式,不然的话,会出现中文显示乱码。可用如下python脚本进行转换。

import os
 
path_dir = "./python_test/geshi"
for root,dirs,files in os.walk(path_dir):
	for file_name in files:
		filename = os.path.join(root,file_name)
		content = "".join(open(filename).readlines())
		try:
		content = content.decode("utf8").encode("gbk",'ignore')
		except:
			print "filename not utf8"
			continue
		f = open(filename,"w")
		f.write(content)
		f.close()

注:content = content.decode("utf8").encode("gbk",'ignore') ,encode中加入了"ignore"参数,是因为自动转换的时候,有的编码转换不成gbk,我们在自动转后,发现有乱码,可自行手动修改。

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页