如何在C++猜词游戏中判定重复答案为错误并禁止重复得分?
猜词游戏重复答案判定问题
我是编程新手,正在用C++开发一款猜词游戏。需求是:将玩家重复提交的答案判定为错误,且无法重复获得该单词的分数。我尝试过手动编写组合判断的方式,但因组合过多难以实现,附上当前代码及尝试的代码,寻求解决方案。
当前代码
#include <iostream> #include <string> using namespace std; int main() { int firstQPoint, secondQPoint, thirdQPoint, mane; char yourChoice, levelChoice, goBack; string yourFirstAnswer, yourSecondAnswer, yourThirdAnswer; gameMenu: cout << " GUESS THE WORD GAME"; cout << " MADE BY GROUP FIVE"; cout << " 1. PLAY | ENTER \"1\" TO PLAY "; cout << " 2. QUIT | ENTER \"2\" TO QUIT "; cout << " 3. RULES | ENTER \"3\" TO SEE THE RULES"; cout << " What Do You Want To Do : "; cin >> yourChoice; if (yourChoice == '1') { cout << " GUESS THE WORD GAME"; cout << " MADE BY GROUP FIVE"; selectALevel: cout << " OKAY, CHOOSE A LEVEL (1-3) : "; cin >> levelChoice; switch (levelChoice) { case ('1'): cout << " GUESS THE WORD GAME"; cout << " MADE BY GROUP FIVE"; cout << " GIVE 3 BODY PARTS THAT STARTS WITH LETTER \"T\""; cout << "1 : "; cin >> yourFirstAnswer; if (yourFirstAnswer == "TOE", "TONGUE", "TOOTH") { cout << " NICE, YOU GOT A POINT!"; firstQPoint = 1 + 0; } cout << "2 : "; cin >> yourSecondAnswer; if (yourSecondAnswer == "TOE", "TONGUE", "TOOTH") { cout << " NICE, YOU GOT A POINT!"; secondQPoint = 1 + firstQPoint; } cout << "3 : "; cin >> yourThirdAnswer; if (yourThirdAnswer == "TOE", "TONGUE", "TOOTH") { cout << " NICE, YOU GOT A POINT!"; thirdQPoint = 1 + secondQPoint; } break; case ('2'): break; case ('3'): break; default: goto selectALevel; } } else if (yourChoice == '3') { do { cout << " GUESS THE WORD RULES"; cout << " 1. ONLY USE UPPERCASE LETTERS"; cout << " 1. ONLY USE SINGULAR WORDS"; cout << " ENTER \"1\" TO GO BACK : "; cin >> goBack; if (goBack == '1') { goto gameMenu; } } while (goBack != '1'); } else if (yourChoice == '2') { cout << " Okay, Goodbye!"; } return 0; }
尝试的代码
#include <iostream> using namespace std; int main() { int number, again; cout << "give 2 number"; cin >> number; cout << "again :"; cin >> again; if (number == 1 && again == 2) { cout << "correct"; else if (number == 2 && again == 1) { cout << "correct"; } } }
内容的提问来源于stack exchange,提问作者John Carlo Nayan
相关产品推荐
相关产品推荐

