Cでyesまたはnoの質問をするにはどうすればよいですか?
このコードは、ユーザー名を取得して文字列にすることになっています (これは機能します)。その後も続き、旅を始める準備ができているかどうかをユーザーに尋ねます (単純なテキスト アドベンチャー ゲームになります)。
残念ながら、これは機能しません。方法がわからないので、はい/いいえの質問をすることはできません。Google 検索と 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;
}