-7
我正在尝试做一个小游戏,我是一个初学者。C++ if/else undeclared标识符,试图用文字
问题是与ifs和其他,它说“夫人”和“先生”的部分。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string playerName;
int age;
int playerGender;
cout << "Are you a Lady or a Sir?" << endl;
cin >> playerGender;
if (playerGender = Lady)
{
cout << "So you're a girl. " << endl;
}
else if (playerGender = Sir)
{
cout << "So you're a boy." << endl;
}
cout << "What is your name " << playerGender << "?" << endl;
cin >> playerName;
cout << "What is your age?" << playerName << endl;
cin >> age;
if (age <= 10)
{
cout << "You're too young " << playerName << "! " << endl;
}
else if (age >= 11)
{
cout << "You are old enough to play" << playerName << ". " << endl;
这就是我所拥有的,我不知道什么是错的。请帮助!
'playerGender = Lady'是一项任务,不是平等检查。还有什么/哪里是“女士”的定义(或者他们的字符串来检查,但你忘了报价 - 但playerGender是一个'int'不是一个字符串......?) – John3136
What @ john3136的意思是,假设一个“ Lady“是一个实际定义的东西,你会希望这是'if(playerGender == Lady)...' –
当你尝试编译时究竟发生了什么?你看到什么错误或警告? – owacoder