由于值返回函数中的错误,程序无法编译.它说未声明的标识符
Program not compiling due to error in the value returning function. It says undeclared identifier
我正在为石头剪刀布编写一个程序,其中有一个用户播放器和一个计算机播放器。我相信一切都很好,直到布尔值返回函数。它需要两个参数(计算机的选择,玩家的选择(,看看它们是否等于打印出"平局"。但是,我收到一个错误,指出我的两个参数的未声明标识符。
我尝试将其更改为 int 函数而不是 bool。 并将我的布尔语句放在 main 中,但它不起作用
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
int getComputerChoice();
int getPlayerChoice();
bool isTie (int, int);
int main()
{
char choice;
int compChoice;
int plaChoice;
do
{
cout << "ROCK PAPER SCISSORS MENU" << endl;
cout << "--------------------------" << endl;
cout << "p)Play Game" << endl;
cout << "q)Quit" << endl;
cout << "Please enter your choice : " << endl;
cin >> choice;
while (choice != 'p' && choice != 'q')//or if//why &&
{
cout << "Invalid selection. Try again." << endl << endl << endl;
cin >> choice;
}
switch (choice)
{
case 'p':
compChoice = getComputerChoice();
plaChoice = getPlayerChoice();
if (plaChoice == 1)
{
cout << "You chose: Rock" << endl;
}
else if (plaChoice == 2)
{
cout << "You chose: Paper" << endl;
}
else
{
cout << "You chose: Scissors" << endl;
}
if (compChoice == 1)
{
cout << "The computer chose: Rock" << endl;
}
else if (compChoice == 2)
{
cout << "The computer chose: Paper" << endl;
}
else
{
cout << "The computer chose: Scissors" << endl;
}
if (isTie(compChoice, plaChoice))
{
cout << "It is a Tie!";
}
break;
case 'q':
cout << "You have chosen to quit the program. Thank you for using the program!" << endl;
break;
}
} while (choice != 'q');
return 0;
}
int getComputerChoice()
{
int comp = 0;
int rando = 0;
srand((unsigned int)time(NULL));
rando = rand() % 3 + 1;
switch (rando)
{
case 1:
comp = 1;
break;
case 2:
comp = 2;
break;
case 3:
comp= 3;
break;
return comp;
}
}
int getPlayerChoice()
{
int player;
cout << "Rock, Paper or Scissors?" << endl;
cout << "1) Rock" << endl;
cout << "2) Paper" << endl;
cout << "3) Scissors" << endl;
cout << "Please enter your choice: " << endl;
cin >> player;
while (player != 1 && player != 2 && player != 3)
{
cout << "Invalid" << endl;
cin >> player;
}
return player;
}
bool isTie(compu, playa)
{
if (compu == playa)
return true;
else
return false;
}
这些是我收到的错误消息 compu':未声明的标识符 Playa':未声明的标识符 "isTie":重新定义;以前的定义是"功能" 参见"isTie"声明 'isTie':函数样式初始值设定项似乎是函数定义
isTie
是一个有2个参数的函数。 从您的代码中,我可以看到它期待 2integers
.
因此,您需要将函数签名更新为:
bool isTie(int compu, int playa)
相关文章:
- 未声明的标识符编译暗黑破坏神 2 程序"muleview"
- 为什么更改包含 psapi.h 的顺序会产生编译错误?(标识符 BOOL 未定义)
- 由于值返回函数中的错误,程序无法编译.它说未声明的标识符
- 为什么在函数参数编译中没有标识符的const关键字
- 结构引用编译错误:预期的标识符或"&"标记之前的"("
- 错误:在编译 cuda 的开源库 cusp 程序时需要标识符
- 编译错误:g++-v4/tr1_impl/type_traits(226):错误:需要标识符
- 在编译时生成唯一的类型标识符
- boost::p roperty_tree 编译错误(错误 C2061:语法错误:标识符"p")
- 在编译时创建一个标识符,其中包含行号作为标识符的一部分
- Xcode 中 DEBUG 标识符上的编译错误
- 编译时未找到"log10"标识符错误
- 语法错误:编译 winnt.h 时缺少标识符'PVOID64'之前的';'
- 在Mac OS上编译Box2D时出错:找不到EGL标识符
- 为什么我的简单 c++ 代码无法编译?我收到未声明的标识符?
- C++编译错误:未定义的标识符(用于函数参数)
- 根据编译时常量,使用相同的标识符 #define 或类型定义是否被认为是可接受的做法?
- 为类型分配唯一的整型标识符,编译时
- c++编译错误预期的标识符在数字常量之前
- RPC_CSTR' :使用 Nmake 编译 C++ 时未声明的标识符