【发布时间】:2013-12-31 10:19:17
【问题描述】:
我想制作一个程序来询问用户问题,然后用户选择一个答案,然后程序返回到原始问题目录。例如:
你最喜欢的颜色是什么? 1. 蓝色 2. 绿色 3. 黄色
然后用户选择说“2”
那我想让它返回
你最喜欢的颜色是什么? 1. 蓝色 2. 绿色 3. 黄色
我已经编写了代码来处理询问、选择问题的答案。我只需要帮助返回到原始问题,以便用户可以根据需要再次回答。谢谢大家!
#include <stdio.h>
int main (void)
{
printf("\nIntroducing Space\n");
printf("Brought to you in part by Free Time\n\n\n");
while(1) {
int space;
int subspace1;
int subspace2;
printf("What would you like to do in Space?\n");
printf("\nDIRECTORY\n\n");
printf("1. What is space?\n");
printf("2. Tell me how cool I am\n");
printf("Enter the number to your desired space\n");
scanf("%i", &space);
if (space == 2){
printf("Although I have never met you, anyone in space would be considered cool to the average eye. I mean lets be real, its space.\n\n");
printf("Do you have any interesting hobbies or tidbits about yourself?\n\n");
printf("1. I can play the flute blindfolded\n");
printf("2. I can eat twelve pounds of salt water taffy in one sitting\n");
printf("3. My uncle drives an RV\n");
scanf("%i", &subspace2);
if (subspace2 == 1) {
printf("\n The flute huh? You're somethin' else\n");
}
if (subspace2 == 2) {
printf("\n But let's be honest who likes salt water taffy these days anyway?\n");
}
if (subspace2 == 3) {
printf("\n An RV? Now adays they call that 'homeless' but hey whatever floats your boat chief\n");
}
}
}
return 0;
}
我觉得这是我需要某种返回语句的地方,它让我回到我最初的问题“你想在太空中做什么”,以便用户可以提出另一个问题。
【问题讨论】:
-
请向我们展示您编写的代码。
-
这背后的逻辑是什么?您想何时返回上一个通话?每次都想要吗?
-
对不起,我很难解释自己是我的错。我用我当前的代码编辑了我的原始帖子
-
@Jekyll 我想做的是问用户“你想做什么?”并给用户选项。在用户选择某样东西后,我想让程序说“你想做点别的吗?”并返回到原来的待办事项目录
-
首先将所有内容放在一个大的 while(1) { } 循环中,然后您可以使用子循环来改进