c语言是面向过程的,不像java,没有好看的界面,但是代码的执行效率很高.
没有用指针的,由于没有学到文件操作部分,涉及到存储的功能暂时无法实现,但是里面有修改密码的模块了.
独立想出来的,用了近六个小时.大部分花在了调试与界面美化上了.
#include<stdio.h>
#include<string.h>
static float balance=0.00; /*静态全局变量*/
static char password[10]="pengyuan";
void printstar(int Num) /*用于打印星号的自定义函数*/
{
int i;
for(i=0;i<Num;i++)
printf("*");
}
void deposit(void) /*用于存款的函数模块*/
{ /*有些语句纯粹是为了美化下界面*/
float a1;
printf("/nPlease input the amount:/n");
scanf("%f",&a1);
balance+=a1;
printf("/n/nDeposit Successfully!");
printf(" **BANK OF CHINA**/n");
}
void withdraw(void) /*用于取款的函数模块*/
{
float a2;
printf("/nPlease input the amount:/n");
scanf("%f",&a2);
if(a2<=balance)
{
balance-=a2;
printf("/n/nWithdraw Successfully!");
printf(" **BANK OF CHINA**/n");
}
else printf("/nERROR! You Cannot Do It!");
}
void Balance(void) /*用于余额查询的函数模块*/
{
printf("/n/nBalance is %.2f",balance);
printf(" **BANK OF CHINA**");
if(balance<100)
{
printf("/nYour Balance Is Low!/n");
printf("Please Deposit More Money!/n");
}
else if(balance>10000)
{
printf("/nYour Balance Is High!/n");
printf("For Safe Don't Deposit Any Money More!/n");
}
}
void change_password(void) /*用于修改密码的函数模块,可惜还没
{ 有学到文件操作部分,以后完善*/
int i;
char string1[10];
printf("/nPlease input your new password:/n");
scanf("%s",string1);
for(i=0;string1[i]!='/0';i++)
password[i]=string1[i];
do
{
password[i]='/0';
i++;
}while(i<10);
printf("/nChange Has Been Done Successfully! **BANK OF CHINA**/n");
}
void function(void) /*自定义的函数,若密码正确,则执行该函数*/
{
int i;
printf("/n");
printstar(15);
printf("/nWelcome to use!");
printf(" **YOUR FINANCIAL ASSISTANT/n");
printstar(15);
printf(" BANK OF CHINA**/n");
printf("/n/n");
printstar(38);
printf("/nUsername: Peng Yuan/n");
printf("Bank: Bank Of China/n");
printf("Address: South Campus Of CSU,Changsha/n");
printstar(38);
for(i=0;;i++)
{
int m;
printf("/n/nPlease Choose Your Operation:");
printf(" **BANK OF CHINA**/n");
printstar(35);
printf("/n1.Deposit 2.Withdraw 3.Balance/n");
printf("4.Change Password 0.Safe Exit/n");
printstar(35);
printf("/n");
scanf("%d",&m);
switch(m)
{
case 1:deposit();break;
case 2:withdraw();break;
case 3:Balance();break;
case 4:change_password();break;
case 0:printf("/nThanks For Use! Welcome Next Time!");
getch();
exit(0);
default :printf("/nYour Operation Was Wrong!/n");
printf("Please Retry It!/n");break;
}
}
}
main() /*主函数放在最后,尽量模块化*/
{
int i;
char string2[10];
for(i=1;i<=2;i++) /*for循环用于控制密码的输入次数*/
{
printf("Please Input Your Password:/n");
gets(string2);
if(strcmp(password,string2)==0)
function();
else printf("/nYour Password Is Wrong!/nPlease Retry It!/n/n");
}
printf("Please Input Your Password For The Last Time Today!:/n");
gets(string2);
if(strcmp(password,string2)==0)
function();
printf("/nStill Wrong!!!/nSorry! You Cannot Enter The Account Today!/n");
printf("/nPress any key to exit.../n");
getch();
}