我不确定如何准确分配我想要的值

I'm not sure how to assign the values I want exactly

本文关键字:我想要 分配 何准确 不确定      更新时间:2023-10-16

我需要在案例陈述中随机挑选樱桃、橙子、羽毛、铃铛、甜瓜或条形图,然后我可以显示选择的内容,以便我可以比较它们,但我不确定如何。

例如,我希望在打印插槽 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
  1. 您已经为所有各种水果声明了字符串,但没有为它们分配任何实际的字符串值。 即string cherries = "cherries"

  2. 仅打印 slot1 只会打印您发现的 int。C++不知道您也想打印名称。您需要将字符串作为 cout 语句的一部分包含在