通过多种功能实现猜字游戏
# include & ltiostream & gt
# include & lt算法& gt
# include & ltcstdlib & gt
# include & lt字符串& gt
使用命名空间std
void show_menu() {
string msg[] = {"1玩游戏"," 2套游戏"," 3退出游戏" };
for(int I = 0;我& lt3;++i) {
cout & lt& ltmsg[I]& lt;& ltendl
}
}
void guess_game(int try_time) {
char ch1,ch2
int CNT = 0;
srand(time(NULL));
ch 1 =(char)(random()% 26+' a ');
做{
CIN & gt;& gtch2
if(ch1 == ch2) {
cout & lt& lt“对”& lt& ltendl
}
否则{
cout & lt& lt“错了”& lt& ltendl
}
++ CNT;
}
while(CNT & lt;尝试时间& amp& ampch1!= CH2);
}
int main() {
int user _ opt = 0;
无符号int try _ time = 3;
show _ menu();
CIN & gt;& gtuser _ opt
开关(用户选项){
案例1:
猜测_游戏(尝试_时间);
打破;
案例二:
cout & lt& lt“输入最大次数”& lt& ltendl
CIN & gt;& gttry _ time
打破;
案例三:
打破;
默认值:
;
}
}