Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将随机整数添加到总数?_C++ - Fatal编程技术网

C++ 将随机整数添加到总数?

C++ 将随机整数添加到总数?,c++,C++,我正在做一个类似21点的程序。我首先生成一对随机的卡片,并存储所有的数字。如果用户愿意,则必须生成另一张卡,并且需要更新新的总数。以下是迄今为止的计划: /* 科尔特斯凤凰酒店 2021年1月25日 CS10B,哈登先生 作业2.1 这个程序使用。。。 */ #包括 #包括 #包括 #包括 #包括 使用名称空间std; int main() { srand(静态_-cast(时间(nullptr)); 串卡选择; 字符串重复选择; int num_1=rand()%10+1; int num_2

我正在做一个类似21点的程序。我首先生成一对随机的卡片,并存储所有的数字。如果用户愿意,则必须生成另一张卡,并且需要更新新的总数。以下是迄今为止的计划:

/*
科尔特斯凤凰酒店
2021年1月25日
CS10B,哈登先生
作业2.1
这个程序使用。。。
*/
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
srand(静态_-cast(时间(nullptr));
串卡选择;
字符串重复选择;
int num_1=rand()%10+1;
int num_2=rand()%10+1;
int total=num_1+num_2;

cout您需要为加法和赋值运算符添加括号,如下所示。(我认为您的意思是
+=
而不是
=+
,但我没有在代码中更改它。)

#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
srand(静态_-cast(时间(nullptr));
串卡选择;
字符串重复选择;
int num_1=rand()%10+1;
int num_2=rand()%10+1;
int total=num_1+num_2;

CUT提示:操作符<代码> = +>代码>(如果存在),因为C++是区分大小写的,“Y”不同于“Y”。你可能想要一些类似的东西:<代码> CARDIONSEORT = ToLoWar(CARDYORADY);< /Cuth>酷,你复制了相同的语法错误,<代码> Toe= +RAND()% 10 + 1 。
#include <iostream>
#include <ctime>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
    srand(static_cast<unsigned>(time(nullptr)));

    string card_choice;
    string repeat_choice;
    int num_1 = rand()%10+1;
    int num_2 = rand()%10+1;
    int total = num_1 + num_2;

    cout << "First Cards: " << num_1 << ", " << num_2;
    cout << "\nTotal: " << total << "\n\n";

    do{
    cout << "Do you want another card? (y/n) ";
    cin >> card_choice;
    }
    while (card_choice == "y" && (total =+ rand()%10+1));

    if (card_choice == "y")
        cout << "\nplay more\n";

    if (card_choice == "n")
        cout << "\nDo you want to play again?\n";


    /*cin >> choice;
    total += choice;
    cout << total;*/

    return 0;
}