【发布时间】:2023-04-03 17:00:03
【问题描述】:
所以我正在创建一个刽子手游戏并想将一个字符添加到一个字符串中。我想在gatherguess 字符串中添加一个猜测字符,直到gatherguess 匹配刽子手。随意在我的代码中添加一些有用的提示,这将使我变得更好。另外,如果您还可以给我一些具有动态内存分配的示例代码,那就更好了。
#include <stdio.h>
#include <string.h>
#include <iostream> // std::cout
#include <stdio.h>
#include <string.h>
#include <iostream> // std::cout
#include <algorithm> // std::for_each
#include <vector>
#include <set>
#include <string>
bool isitdone(std::string foo, std::string hang){
return foo == hang ? true : false ;
}
int main(){
std::string hangman;
char guess;
std::string gatherguess; //Get the letters guessed.
std::cin >> hangman; //Player enter the word to guess.
bool checkstatement; // Check to see if game is over.
for(int i =0; i < 10; ++i) {
std::cin >> guess; //Individual characters to guess
std::string doo;
int wordsin;
doo = hangman;
int y;
if(doo.rfind(guess) != std::string::npos) {
std::cout << "Right " << guess << " Is in the word" << std::endl;
std::cout << std::endl;
checkstatement = isitdone(gatherguess,doo);// I want to add guess char into gatherguess
//then check to see if gatherguess is equal to the word then the game will be complete
if(checkstatement == true) {
return 0;
}
} else {
std::cout << "Wrong" << std::endl;
}
}
return 0;
}
【问题讨论】:
-
这么多格式化你的代码......
-
Stack Overflow 不是免费的在线代码修复服务。首先展示您的调试工作!考虑在这里询问作为最后的手段,展示你为解决问题所做的所有努力,并清楚地说明你卡在哪里。以minimal reproducible example 开头,否则这里不欢迎您提出问题。