C语言综合设计—ATM机操作

源代码:

#include
#include
#include
void Query();
void MainMenu(); 
void Withdraw();
void Deposit();
int flag=1;
int *p=&flag;
char codestr[10]="12345678";
float save=1000.0;
void code();


void code()
{
int i=0;
int flag;
char str[20];
printf("请输入您的密码\n");
for(i=0;i<20;i++)
{
str[i]=getch();
if(str[i]=='\r')
break;
printf("*");
}
str[i]='\0';
i=0;
while(str[i]!='\0')
{
if(str[i]!=codestr[i])
{
flag=0;
break;
}
i++;
}
system("cls");
if(flag==0)
{
printf("密码错误!\n");
system("pause");
system("cls");
code();
}
if(flag==1)
printf("欢迎您的登陆!\n");


}




int main()
{
code();
while(flag)
{
MainMenu();
int b1;
switch(b1=getch())
{
case'1':
Query();
break;

case'2': Deposit();
break;

case'3': Withdraw();
break;


case'4': flag=0;
system("cls");
printf("感谢您的使用!\n");
break;
}
system("cls");
}
return 0;
}




void Withdraw()
{
if(*p == 1)
{
float defacit;
float withdraw;
system("cls");
printf(" 您的余额为 %.1f 元 \n",save);
printf("\n请输入您想要取出的数量\n");
scanf("%f",&withdraw);
defacit=save-withdraw;
if(defacit<0)
{ printf("对不起,您的余额不足\n"); }
if(defacit>=0)
{
save=save-withdraw;
printf("您已经成功取出%.1f元\n",withdraw);
}
system("pause");
}


else if(*p == 2)
{
float defacit;
float withdraw;
system("cls");
printf(" you have %.1f ¥\n",save);
printf("\nPlease input the nuber you want to withdraw\n");
scanf("%f",&withdraw);
defacit=save-withdraw;
if(defacit<0)
{ printf("Sorry, your balance is not enough\n"); }
if(defacit>=0)
{
save=save-withdraw;
printf("You have already taken out%.1f\n¥",withdraw);
}
system("pause");
}


}




void Deposit()
{
system("cls");
int deposit;
if(*p == 1)
{
printf("\n请输入您想要存入的数量:");
scanf("%d",&deposit);
save+=deposit;
}
else if(*p == 2)
{
printf("\nPlease input the number you want to save:");
scanf("%d",&deposit);
save+=deposit;
}


}


void Query()
{


printf("\n%d",*p);
if(*p == 1)
{
system("cls");
printf("\n您的余额为%.1f元.\n",save);
}
else if(*p == 2)
{
system("cls");
printf("\nyour balance is %.1f ¥\n",save);
}
system("pause");
}

void MainMenu()
{
printf("\n\n\t\t\t   欢迎使用任式ATM机,请按照如下进行操作\n\t\t\t=========================================\n\t\t\t|\t\t1.中文\t\t\t|\n|\t\t\t|\t\t2.English\t\t|\n|\t\t\t|\t\t3.退出/Exit\t\t|\n\t\t\t=========================================\n\t\t\t\t");
//do we really need to do like this  ?
flag=getch();
switch(flag)
{
case'1':
{
*p=1;
system("cls");
printf("\n\n\t\t\t=========================================\n\t\t\t|\t\t1.查询\t\t\t|\n|\t\t\t|\t\t2.存钱\t\t\t|\n|\t\t\t|\t\t3.取钱\t\t\t|\n\t\t\t|\t\t4.退出\t\t\t|\n\t\t\t=========================================\n\t\t\t\t");
break;
}
case'2':
{ *p=2;
system("cls");
printf("\n\n\t\t\t=========================================\n\t\t\t|\t\t1.Query\t\t\t|\n|\t\t\t|\t\t2.Deposit\t\t|\n|\t\t\t|\t\t3.Withdraw\t\t|\n\t\t\t|\t\t4.Exit\t\t\t|\n\t\t\t=========================================\n\t\t\t\t");
break;
}
case'3': 
{
system("cls");
printf("\n\n\t\t\t感谢您的使用!\n\t\t\t");
exit(0);

}
}




}

你可能感兴趣的:(程序代码)