-2
警告:我是编程新手!我正在尝试为类项目创建一个随机信发生器游戏。我觉得我有一个体面的开局,但我有几点困难。随机信发生器游戏
该程序应该问玩家他们想玩多少游戏(1-5)。他们每场比赛得到的最大猜测数是5,然后如果它没有被猜出,它应该打印出正确的答案。事实上,我拥有它,以便它能够运行正确的猜测数量,但不是游戏,并且当所有猜测都完成时,它是正确的答案。任何帮助表示赞赏,谢谢。
#include<iostream>;
#include<cstdlib>;
#include<ctime>;
using namespace std;
int main()
{
char alphabet [27];
int number_of_games;
char guess;
int x = 1;
srand(time(0));
int n = rand() % 26 + 1;
cout<<"Weclome to the Letter Guessing game!\n";
cout<<"You have 5 chances to guess each letter.\n \n";
cout<<"How many games do you want to play?\n";
cin >> number_of_games;
cout<<"**************************************************\n\n";
while (x <= number_of_games) //Need to get it for how many rounds, not how many guesses
{
if (number_of_games < 1)
{
cout<< "Lets play game " << number_of_games << '\n';
}
//cout << (char)(n+97); //cheat to make sure working
cout<<"Enter your guess: ";
cin >> guess;
int guessValue = int(guess);
if (guessValue > (n+97))
{
cout<<"The letter you are trying to guess is before " <<guess <<"\n";
}
else if (guessValue < (n+97))
{
cout<<"The letter you are trying to guess is after " <<guess << "\n";
}
else if( (char)(n+97))
{
cout << "The answer you were looking for was " << (char)(n+97) << "\n";
}
else
{
cout<<"Your guess is correct! \n";
break;
}
//if answer is not right after x tries, cout the correct answer
x++;
}
system("pause");
return 0;
}
谢谢您的帮助!你的建议工作得很好@JohnnyMopp – Brittany