【发布时间】:2019-08-20 01:18:35
【问题描述】:
当我运行代码时,我的两个选项都会出现
我尝试了两个 if 语句 else if 和 else
cout << "would you like to hit or stand?" << endl; //asking if you would ike to hit or stand
bool hit; //the hjitting opption
bool stand; // the stand / hit option
cin >> hit, stand; // the avaiabillity for hitting or standing (player input)
if ( hit = true) // if you hit
{
for (n = 1; n <= 1; n++) //loop for how many cards are you have
{
num = rand() % 13; //get random number
cout << num << "\t"; //outputting the number
}
}
{
cout << "you stand \n"; // saying you stand
我希望代码在你说击中时输出数字,当你说站立时说你站着,但它要么只是击中,要么只是击中支架,要么两者都输出enter code here
【问题讨论】:
-
尝试在左侧写条件
if(true = hit) -
cin >> hit, stand;不会像您认为的那样做。您正在尝试输入单个字符串,对吗?然后你想在单独的 if 语句中将它与字符串“hit”和字符串“stand”进行比较。 -
我没有看到任何“其他”陈述。您还必须使用 == 进行比较。
-
看来你可以使用a couple of good books阅读。
标签: c++ if-statement blackjack