C语言 switch菜单 输入后继续输入,C++ switch 语句回到主菜单后,如何能让第一次执行所保留的值下次可以继续使用?...

C++ switch 语句回到主菜单后,如何能让第一次执行所保留的值下次可以继续使用?0

dcebd7a0de6265b6ccae5ead692f1eab.pngxbtyxjam2017.01.02浏览45次分享举报

#include

using namespace std;

int input()

{

char name;

float weight;

int age;

char favouritefood;

cout<< "please input the name, weight(kg), age, favourite food in order\n";

cin >> name >> weight >> age >> favouritefood;

return 0;

}

int read()

{

char name;

float weight;

int age;

char favouritefood;

cout<< "the name is" << name;

cout<< "\n the weight is" << weight << "(kg)";

cout<< "\n the age is" << age;

cout<< "\n the favourite food is" << favouritefood;

return 0;

}

——————下面是重点————————

int main()

{

char choice;

cout<< "what do you want? \n";

cout<

cin >> choice;

switch (choice)

{

case 'a':

input();

return main();

case 'b':

read ();

return main();

case 'q':

cout<< "Thank you. Goodbye!!!";

default:

break;

}

}

我想要的是第一次我输入a保存值之后,我接着输入b可以读到之前的值,但是实际中我的第一次选了a之后跳出循环,下次再选b的时候上次输入的值就得不到了。求大神帮忙!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值