如何在 C 中提出是或否的问题?
该代码应该采用用户名并将其设为字符串(有效)。然后它继续询问用户是否准备好开始他们的旅程(这将是一个简单的文字冒险游戏)。
不幸的是,这不起作用。我无法提出是/否的问题,因为我不知道该怎么做。谷歌搜索和搜索 StackOverflow 也没有帮助我。
这是我迄今为止所拥有的:
#include <stdio.h>
int main()
{
/*This declares the strings*/
char name[20];
char yesno[3];
char choice[1];
/*This tells the user that they should only use Y/N when responding to Yes or No questions.*/
printf("When responding to Yes or No questions use Y/N.\n");
/*This asks the user what their name is and allows the program to use it as a string for the rest of the program*/
printf("Hello! What is your name?\n");
scanf("%s",name);
printf("Hello %s, are you ready for your journey?\n",name);
scanf("%c",choice);
char choice, 'Y';
while (choice != 'N' && choice == 'Y')
{
printf("Okay!Let's continue %s.\n",name);
}
char choice,'N';
while (choice != 'Y' && choice == 'N')
{
printf("Goodbye.\n");
}
return 0;
}