#include <stdio.h> // Структура для представления карты typedef struct { char* rank;…
- User
#include <stdio.h>
// Структура для представления карты typedef struct { char* rank; char* suit; } Card;
// Массив для мастей и рангов const char* suits[] = {"Pick", "Tref", "Bubn", "Chervi"}; const char* ranks[] = {"7", "8", "9", "10", "V", "D", "K", "T"};
int ask_question(const char* question) { char answer; printf("%s (Yes/No): ", question); while (scanf(" %c", &answer) != 1 || (answer != 'Y' && answer != 'y' && answer != 'N' && answer != 'n')) { printf("Please answer 'Yes' or 'No': "); while (getchar() != '\n'); // Очищаем буфер ввода }
return (answer == 'Y' || answer == 'y') ? 1 : 0;}
void guess_card() { int suit_index = 0; int rank_index = 0;
if (ask_question("Is your card Pick or Tref?")) { if (ask_question("Is your card Pick?")) { suit_index = 0; } else { suit_index = 1; } } else { if (ask_question("Is your card Bubn?")) { suit_index = 2; } else { suit_index = 3; } } if (ask_question("Is the nominal of your card 7, 8, 9, or 10?")) { if (ask_question("Is the nominal of your card 7 or 8?")) { if (ask_question("Is the nominal of your card 7?")) { rank_index = 0; // 7 } else { rank_index = 1; // 8 } } else { if (ask_question("Is the nominal of your card 9?")) { rank_index = 2; // 9 } else { rank_index = 3; // 10 } } } else { if (ask_question("Is the nominal of your card Valet or Dama?")) { if (ask_question("Is the nominal of your card Valet?")) { rank_index = 4; } else { rank_index = 5; } } else { if (ask_question("Is the nominal of your card King?")) { rank_index = 6; } else { rank_index = 7; } } } printf("Your card: %s of %s\n", ranks[rank_index], suits[suit_index]);}
int main() { printf("Загадайте карту из колоды (32 карты) и ответьте на вопросы 'Yes' или 'No'.\n"); guess_card(); return 0; } Переделай код так чтобы не было конструкций if и while
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.