你忘了<<
?
试试这个:
int raise[] = {1,2,3,4,5,6,7,8,9,10};
int raise_value = rand()%10;
cout << "You get a " << raise[raise_value] << " $ Raise" << endl;
salary += raise[raise_value];
你的字符串gamble
必须std::string
太:
std::string gamble = "You Get A Raise";
这是一个完整的例子:
int salary = 1000;
std::string gamble = "You Get A Raise";
int raise[] = {1,2,3,4,5,6,7,8,9,10};
if (std::strcmp(gamble.c_str(),"You Get A Raise") == 0) {
// or
// if (gamble.compare("You Get A Raise") == 0) {
int raise_value = rand()%10;
cout << "You get a " << raise[raise_value] << " $ Raise" << endl;
salary += raise[raise_value];
cout << "New salary is $" << salary << endl;
}
你得到什么错误? – jready
不同的指针类型之间的比较std :: string * –