c语言怎么从调用函数回到主函数
#include"stdio.h"#include"string.h"struct account{ char name[20]; int money;}accounts;void plm(){ printf("您账户的余额:%d",accounts.money);}void qwe(){ int cunkuan; printf("请输入存款金额:"); scanf("%d",&cunkuan); accounts.money=cunkuan+accounts.money; printf(" 存款成功!\n账户余额:%d\n",accounts.money);}void poi(){ int qukuan,i; printf("请输入取款金额:"); while(1) { scanf("%d",&qukuan); if(accounts.money<qukuan) { printf("账户余额不足!你的账户余额:%d\n请重新输入:",accounts.money); } else {accounts.money=accounts.money-qukuan; printf("取款成功!\n账户余额:%d",accounts.money);break;} }}void main(){ char name[20]; char mima[20]; int q; printf("====================================================\n"); printf("====================================================\n"); printf("==================欢迎你使用银行系统================\n"); printf("====================================================\n"); printf("====================================================\n\n"); printf("请输入你的账户名:"); gets(name); printf("请输入密码:"); gets(mima); printf("\n"); if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0) { printf("登陆成功!\n"); printf(" 1 存款 2 取款 3 开户\n"); printf(" 4 销户 5 查询 0 退出\n请选择:"); scanf("%d",&q); switch (q) { case 1:{qwe();break;} case 2:{poi();break;} case 3:break; case 4:break; case 5:{plm();break;} case 0:;} } else printf("输入的账户名和密码错误!!");} 展开
#include"stdio.h"
#include"string.h"
struct account
{
char name[20];
int money;
}accounts;
void plm()
{
printf("您账户的余额:%d",accounts.money);
}
void qwe()
{
int cunkuan;
printf("请输入存款金额:");
scanf("%d",&cunkuan);
accounts.money=cunkuan+accounts.money;
printf(" 存款成功!\n账户余额:%d\n",accounts.money);
}
void poi()
{
int qukuan,i;
printf("请输入取款金额:");
while(1)
{
scanf("%d",&qukuan);
if(accounts.money<qukuan)
{
printf("账户余额不足!你的账户余额:%d\n请重新输入:",accounts.money);
}
else
{
accounts.money=accounts.money-qukuan;
printf("取款成功!\n账户余额:%d\n",accounts.money);
break;
}
}
}
void main()
{
char name[20];
char mima[20];
int q;
printf("====================================================\n");
printf("====================================================\n");
printf("==================欢迎你使用银行系统================\n");
printf("====================================================\n");
printf("====================================================\n\n");
printf("请输入你的账户名:");
gets(name);
printf("请输入密码:");
gets(mima);
printf("\n");
if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0)
{
printf("登陆成功!\n");
int t=1;
while(t)//主函数加上一个while循环就好了,t表示是否继续使用系统,选择0时,t=1,即可退出系统了
{
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
scanf("%d",&q);
switch (q)
{
case 1:
{
qwe();
break;
}
case 2:
{
poi();
break;
}
case 3:
break;
case 4:
break;
case 5:
{
plm();
break;
}
case 0:
{
t=0;
break;
}
}
}
}
else
printf("输入的账户名和密码错误!!");
}
给你改了一下,参考吧。
#include"stdio.h"
#include"string.h"
#include<stdlib.h>
struct account
{
char name[20]; int money;
}accounts;
void plm()
{
printf("您账户的余额:%d",accounts.money);
}
void qwe()
{
int cunkuan;
printf("请输入存款金额:");
scanf("%d",&cunkuan);
accounts.money=cunkuan+accounts.money;
printf(" 存款成功!\n账户余额:%d\n",accounts.money);
}
void poi()
{
int qukuan,i;
printf("请输入取款金额:");
while(1)
{
scanf("%d",&qukuan);
if(accounts.money<qukuan)
{
printf("账户余额不足!你的账户余额:%d\n请重新输入:",accounts.money);
}
else
{
accounts.money=accounts.money-qukuan;
printf("取款成功!\n账户余额:%d",accounts.money);
break;
}
}
}
void main()
{
char name[20];
char mima[20];
int q;
printf("====================================================\n");
printf("====================================================\n");
printf("==================欢迎你使用银行系统================\n");
printf("====================================================\n");
printf("====================================================\n\n");
printf("请输入你的账户名:");
gets(name);
printf("请输入密码:");
gets(mima);
printf("\n");
if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0)
{
printf("登陆成功!\n");
while(1)
{
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
scanf("%d",&q);
if(q==0)
break;
switch (q)
{
case 1:
qwe();
system("PAUSE");
break;
case 2:
poi();
system("PAUSE");
break;
case 3:
break;
case 4:
break;
case 5:
plm();
system("PAUSE");
break;
default:
break;
}
system("CLS");
}
}
else
printf("输入的账户名和密码错误!!");
}
2014-01-20
if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0) {
printf("登陆成功!\n");
while(6-q){
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
scanf("%d",&q);
switch (q) {
case 1:{qwe();break;}
case 2:{poi();break;}
case 3:break;
case 4:break;
case 5:{plm();break;}
case 6:;
}
}
}
else printf("输入的账户名和密码错误!!");
//while 语句可以实现某一处的循环多次调用的
2014-01-20
#include"stdio.h"
#include"string.h"
struct account
{
char name[20];
int money;
}
accounts;
void plm()
{
printf("您账户的余额:%d",accounts.money);
}
void qwe()
{
int cunkuan;
printf("请输入存款金额:");
scanf("%d",&cunkuan);
accounts.money=cunkuan+accounts.money;
printf(" 存款成功!\n账户余额:%d\n",accounts.money);
}
void poi()
{
int qukuan,i;
printf("请输入取款金额:");
while(1) { scanf("%d",&qukuan);
if(accounts.money<qukuan) { printf("账户余额不足!你的账户余额:%d\n请重新输入:",accounts.money); }
else {accounts.money=accounts.money-qukuan; printf("取款成功!\n账户余额:%d",accounts.money);break;} }
}
int main()
{
char name[20];
char mima[20];
int q;
printf("====================================================\n");
printf("====================================================\n");
printf("==================欢迎你使用银行系统================\n");
printf("====================================================\n");
printf("====================================================\n\n");
printf("请输入你的账户名:");
gets(name);
printf("请输入密码:");
gets(mima);
printf("\n");
if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0)
{
printf("登陆成功!\n");
while(1)
{
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
scanf("%d",&q);
switch (q)
{
case 1:
{qwe();break;}
case 2:
{poi();break;}
case 3:break;
case 4:break;
case 5:{plm();break;}
case 0:
return 0;
}
}
}
else printf("输入的账户名和密码错误!!");
return 0;
}
{
char name[20];
char mima[20];
int q;
printf("====================================================\n");
printf("====================================================\n");
printf("==================欢迎你使用银行系统================\n");
printf("====================================================\n");
printf("====================================================\n\n");
printf("请输入你的账户名:");
gets(name);
printf("请输入密码:");
gets(mima);
printf("\n");
if(strcmp(name,"zengxin")==0&&strcmp(mima,"12345")==0)
{
printf("登陆成功!\n");
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
while(scanf("%d",&q) != EOF && 0 != q )
{
switch (q)
{
case 1:
{
qwe();
break;
}
case 2:
{
poi();
break;
}
case 3:
break;
case 4:
break;
case 5:
{
plm();
break;
}
case 0:
;
}
printf(" 1 存款 2 取款 3 开户\n");
printf(" 4 销户 5 查询 0 退出\n请选择:");
}
}
else printf("输入的账户名和密码错误!!");
}
稍微改了一下你的主函数