2016-01-05 31 views

回答

0

你忘了<<

试试这个:

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; 
} 
+0

糟糕,但我得到了指针类型和std :: string之间的另一个错误比较相同的错误,但它添加了无效的转换从int *到int –

+0

@MichaelWebb - 请参阅更新 –

+0

@MichaelWebb - 如何定义“赌博”? –

0

你居然要STOR e加薪指数:rand()%10为了显示,然后将同样的加薪应用于薪水。

int raise[] {1,2,3,4,5,6,7,8,9,10}; 
int raiseIdx = rand()%10; 
cout << "You get a " << raise[raiseIdx] << " $ Raise" << endl; 
salary = salary + raise[raiseIdx]; 

gamble变量应该是一个std::string

std::string gamble = "You Get A Raise"; 
相关问题