<pre class="cpp" name="code">#include <stdio.h>
char getChoice();
void eat();
void sleep();
void hitdoudou();
void cry();
int main()
{
char cChioce;
while(1)
{
cChioce = getChoice();
if (cChioce=='1')
eat();
else if (cChioce=='2')
sleep();
else if (cChioce=='3')
hitdoudou();
else if (cChioce=='4')
cry();
else if (cChioce=='0')
break;
else
{
printf("\007选择错误!\n");
continue;
}
printf("恭喜你完成了一项工作!\n");
}
return 0;
}
char getChoice()
{
char c;
printf("\n ********************\n");
printf(" * 1. 吃饭 *\n");
printf(" * 2. 睡觉 *\n");
printf(" * 3. 打豆豆 *\n");
printf(" * 4. 找豆豆妈诉苦 *\n");
printf(" * 0. 退出 *\n");
printf(" ********************\n");
printf(" 请选择(0-4):");
fflush(stdin);
scanf("%c", &c);
return c;
}
void eat()
{
printf(" 我吃吃吃... ...\n");
}
void sleep()
{
printf(" 我睡觉觉... ...\n");
}
void hitdoudou()
{
printf(" 我打打打... ...\n");
}
void cry()
{
printf(" 哇! 你家豆豆骨头硬,害得我手疼... ...\n");
}
![](https://img-blog.csdn.net/20151106090424604?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
<pre class="cpp" name="code">#include <stdio.h>
char getChoice();
void eat();
void sleep();
void hitdoudou();
void cry();
int main()
{
char cChioce;
while(1)
{
cChioce = getChoice();
if (cChioce=='1')
eat();
else if (cChioce=='2')
sleep();
else if (cChioce=='3')
hitdoudou();
else if (cChioce=='4')
cry();
else if (cChioce=='0')
break;
else
{
printf("\007选择错误!\n");
continue;
}
printf("恭喜你完成了一项工作!\n");
}
return 0;
}
char getChoice()
{
char c;
printf("\n ********************\n");
printf(" * 1. 吃饭 *\n");
printf(" * 2. 睡觉 *\n");
printf(" * 3. 打豆豆 *\n");
printf(" * 4. 找豆豆妈诉苦 *\n");
printf(" * 0. 退出 *\n");
printf(" ********************\n");
printf(" 请选择(0-4):");
fflush(stdin);
scanf("%c", &c);
return c;
}
void eat()
{
printf(" 我吃吃吃... ...\n");
}
void sleep()
{
printf(" 我睡觉觉... ...\n");
}
void hitdoudou()
{
printf(" 我打打打... ...\n");
}
void cry()
{
printf(" 哇! 你家豆豆骨头硬,害得我手疼... ...\n");
}