Visual c++ 函数程序故障
我的石头剪刀游戏代码有问题,似乎无法缩小它的范围。我认为displayResults函数和getComputerchoice函数存在问题。很抱歉,我是这个类的新手,没有寻找任何人来为我编写代码,但我希望有任何指向正确方向的指点Visual c++ 函数程序故障,visual-c++,Visual C++,我的石头剪刀游戏代码有问题,似乎无法缩小它的范围。我认为displayResults函数和getComputerchoice函数存在问题。很抱歉,我是这个类的新手,没有寻找任何人来为我编写代码,但我希望有任何指向正确方向的指点 #include <iostream> #include <string> using namespace std; int getComputerChoice (); int getUserChoice (); int determineWin
#include <iostream>
#include <string>
using namespace std;
int getComputerChoice ();
int getUserChoice ();
int determineWinner (int userchoice, int compchoice);
void displayResults (int &userchoice, int &compchoice, int &wincode);
string convertchoice (int userchoice, int compchoice);
string convertwin (int wincode);
int main ()
{
int compchoice, userchoice, wincode;
string compname, username, winname;
cout << "Game Menu" << endl;
cout << "---------" << endl;
cout << "1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissors" << endl;
cout << "4) Quit" << endl;
cout << " " << endl;
userchoice = getUserChoice ();
compchoice = getComputerChoice ();
while (userchoice != 4)
{
wincode = determineWinner (userchoice, compchoice);
displayResults (userchoice, compchoice, wincode);
cout << " " << endl;
cout << "=======================================" << endl;
cout << "You selected: " << userchoice << endl;
cout << "The computer selected: " << compchoice << endl;
cout << "Game Winner: " << wincode << endl;
cout << "=======================================" << endl;
cout << "Game Menu" << endl;
cout << "---------" << endl;
cout << "1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissors" << endl;
cout << "4) Quit" << endl;
cout << " " << endl;
cout << "Enter your choice: " << endl;
cin >> userchoice;
compchoice = getComputerChoice ();
}
return 0;
}
int getUserChoice ()
{
int userchoice;
cout << "Enter your choice: " << endl;
cin >> userchoice;
return userchoice;
}
int getComputerChoice ()
{
srand (time(NULL));
compchoice = rand() % 3 + 1;
return compchoice;
}
int determineWinner (int userchoice, int compchoice)
{ if (compchoice == userchoice)
{ return 0;
}
else if (compchoice == 1 && userchoice == 3)
{ return 2;
}
else if (userchoice == 1 && compchoice == 3)
{ return 1;
}
else if (compchoice == 3 && userchoice == 2)
{ return 2;
}
else if (userchoice == 3 && compchoice == 2)
{ return 1;
}
else if (compchoice == 2 && userchoice == 1)
{ return 2;
}
else if (userchoice == 2 && compchoice == 1)
{ return 1;
}
}
void displayResults (int &userchoice, int &compchoice, int &wincode)
{
username = string convertchoice (userchoice);
compname = string convertchoice (compchoice);
winname = string convertwin (wincode);
}
string convertchoice (int userchoice, int compchoice)
{
int choice;
userchoice = choice;
compchoice = choice;
if (choice == 1)
{ return "Rock";
}
else if (choice == 2)
{ return "Paper";
}
else if (choice == 3)
{ return "Scissors";
}
}
string convertwin (int wincode)
{
if (wincode == 1)
{
return "User";
}
else if (wincode == 2)
{
return "Computer";
}
else if (wincode == 0)
{
return "Tie";
}
}
#包括
#包括
使用名称空间std;
int getComputerChoice();
int getUserChoice();
int determineWinner(int userchoice,int compchoice);
无效显示结果(int&userchoice、int&compchoice、int&wincode);
字符串convertchoice(int-userchoice,int-compchoice);
字符串转换器win(int-wincode);
int main()
{
int compchoice、userchoice、wincode;
字符串compname、用户名、winname;
不知道代码中出现问题的具体原因是什么是可以的,但至少应该说明代码的行为有什么问题。在这种情况下,“麻烦”是什么意思?大量未声明的标识符错误和标识符未找到错误以及“函数不带1个参数”错误。这就是我所能详细说明的,我很抱歉。这可能与您的代码使用了大量未声明的标识符有关(例如getComputerChoice
第68行中的compchoice
;或displayResults
第98行中的username
)然后,您有了诸如“代码> UsNeNe= String转换选项(USERead))的代码;只与C++代码远程类似;我很难猜到您在那里尝试做什么。