我不确定如何准确分配我想要的值
I'm not sure how to assign the values I want exactly
我需要在案例陈述中随机挑选樱桃、橙子、羽毛、铃铛、甜瓜或条形图,然后我可以显示选择的内容,以便我可以比较它们,但我不确定如何。
例如,我希望在打印插槽 1、插槽 2 和插槽 3 时,我能得到三个开关中每个开关中每个开关中哪个 case 语句的名称。
不是他们的数字。(该程序尚未完成,因此现在很混乱)
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main()
{
int slot1;
int slot2;
int slot3;
double won;
double money;
string cherries;
string oranges;
string plums;
string bells;
string melons;
string bars;
string doAgain;
do
{
cout << "We are going to be playing a slot machine game today." << endl;
cout << "Please enter the amount of money you'd like to insert into the slot machine." << endl;
cin >> money;
cout << "You put in $" << money << endl;
srand(time(0));
slot1=rand()%6+1;
slot2=rand()%6+1;
slot3=rand()%6+1;
switch (slot1)
{
case 1:
cout << cherries << endl;
case 2:
cout << oranges << endl;
break;
case 3:
cout << plums << endl;
break;
case 4:
cout << bells << endl;
break;
case 5:
cout << melons << endl;
break;
case 6:
cout << bars << endl;
}
switch (slot2)
{
case 1:
cout << melons << endl;
break;
case 2:
cout << bells << endl;
break;
case 3:
cout << bars << endl;
break;
case 4:
cout << plums << endl;
break;
case 5:
cout << oranges << endl;
break;
case 6:
cout << cherries << endl;
}
switch (slot3)
{
case 1:
cout << bars << endl;
break;
case 2:
cout << plums << endl;
break;
case 3:
cout << melons << endl;
break;
case 4:
cout << bells << endl;
break;
case 5:
cout << oranges << endl;
break;
case 6:
cout << cherries << endl;
}
cout << "The numbers you got were " << slot1 << ", " << slot2 << ", " << slot3 << endl;
cout << "Would you like to play again?" << endl;
cin >> doAgain;
if(doAgain!= "yes")
{
cout << "The total amount of money you put in the slot machine is" << money << endl;
cout << "The total amount of money you won is $" << won << endl;
}
}
while(doAgain=="yes");
return 0;
}
enter code here
-
您已经为所有各种水果声明了字符串,但没有为它们分配任何实际的字符串值。 即
string cherries = "cherries"
-
仅打印 slot1 只会打印您发现的 int。C++不知道您也想打印名称。您需要将字符串作为 cout 语句的一部分包含在
内
相关文章:
- 如何设置一个范围来提取我想要获得的信息
- 链接列表运算符重载没有打印出我想要的内容
- 莱克斯没有返回我想要的东西
- 而不是那么多的 if 语句,我想要一个逻辑,我可以用一个语句或优化的方式来完成
- 我想要一个具有子函数的函数访问相同的命名函数,而不使用它取决于其子类的类
- 如何让m_refcount变量打印出我想要的值而不是垃圾
- 我想要一个改变数组快速排序的2个数字的函数
- 输出不是我想要C++的
- 使用运算符覆盖排序没有得到我想要的
- C ++,否则文本程序不会进入我想要的途径
- 如何声明一个未知大小的数组,然后输入直到我想要,然后获取数组的大小
- 我如何使用 juce 的文件过滤器描述我想要的文件过滤器?
- 如何设置此视觉工作室 (2015) 自定义生成步骤(工具?基本上,我想要一个修改头文件(c ++)的预处理器步骤
- 代码不会发送我想要的权衡
- 无法在openGL和GLUT中为我想要的确切对象设置动画
- 我如何强迫Visual Studio使用我想要的依赖性库名称
- 我的 OpenGL QQuickItem 没有我想要的大小
- 我可以/应该在 #ifndef 后输入任何我想要的东西
- 是否有一种方法可以选择我想要分配的一个实例的成员,而无需手动分配它们
- 我不确定如何准确分配我想要的值