Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
Arrays C++;如何从字符串数组元素递增Int变量_Arrays_String_Visual C++_Element_C Strings - Fatal编程技术网

Arrays C++;如何从字符串数组元素递增Int变量

Arrays C++;如何从字符串数组元素递增Int变量,arrays,string,visual-c++,element,c-strings,Arrays,String,Visual C++,Element,C Strings,我想知道在调用特定的字符串数组元素时,是否有一种方法可以增加int变量?我正在做一个有趣的项目,但遇到了障碍。我的项目的目标是有一个程序来确定用户喜欢什么类型的电子音乐。该程序将显示两个DJ,并询问用户他们更喜欢哪一个,或允许他们选择其中任何一个。每个DJ最多有三种类型,他们主要专注于这三种类型,我为每种类型创建了int变量(所有类型都设置为0)。一旦用户选择了一个DJ,我希望将点数分配给与DJ关联的每个流派变量。我不确定如何设置此规则,因为到目前为止我尝试的所有操作都失败了(代码中注释了两个示

我想知道在调用特定的字符串数组元素时,是否有一种方法可以增加int变量?我正在做一个有趣的项目,但遇到了障碍。我的项目的目标是有一个程序来确定用户喜欢什么类型的电子音乐。该程序将显示两个DJ,并询问用户他们更喜欢哪一个,或允许他们选择其中任何一个。每个DJ最多有三种类型,他们主要专注于这三种类型,我为每种类型创建了int变量(所有类型都设置为0)。一旦用户选择了一个DJ,我希望将点数分配给与DJ关联的每个流派变量。我不确定如何设置此规则,因为到目前为止我尝试的所有操作都失败了(代码中注释了两个示例尝试)。最终我的计划是发展逻辑,让DJ的随机选择,但我需要有体裁理货分配设置第一。有什么办法可以做到这一点吗?任何帮助都将不胜感激。干杯

###include "stdafx.h"
###include < iostream>
###include < iomanip>
###include < string>
###include < array>
###using namespace std;



int main()
{
    cout << "Hello! This program is designed to figure out what Electronic Music you like based on artists presented and the answers you choose...\n" << endl;
    cout << "When you are ready to begin press \"Enter\"..." << endl;
    getchar();


int bigRoom = 0;
int deepHouse = 0;
int drumBass = 0;
int dubstep = 0;
int electroHouse = 0;
int futureHouse = 0;
int hardDance = 0;
int house = 0;
int progressiveHouse = 0;
int techno = 0;
int trance = 0;
int trap = 0;

string textArray[5]{ "DeadMau5", "Armin Van Buuren", "Avicii", "Ferry Corsten", "Kaskade"};
string answer;
    cout << "Select the DJ you prefer by number. Otherwise select 3 if you don't know them. " << endl; //Haven't coded option 3 yet.
    cout << "1 - " << textArray[1] << endl;
    cout << "2 - " << textArray[2] << endl;

    cin >> answer;


    /*
    if (textArray[1]) {
        ++trance;
    }

    for (textArray[1]) {
        ++trance;
    }
    */

if (answer == "1") {
    cout << "You have selected: " << textArray[1] << endl;
}

else if (answer == "2") {
    cout << "You have selected: " << textArray[2] << endl;
}


//cout << trance << endl;


}
###包括“stdafx.h”
###包括
###包括
###包括
###包括
###使用名称空间std;
int main()
{

cout用户选择DJ后,您可以增加每个计数:

if (answer == "1") {
    cout << "You have selected: " << textArray[1] << endl;
    ++trance;
    // ++ ohter genres you want to increment
}

else if (answer == "2") {
    cout << "You have selected: " << textArray[2] << endl;
    ++trance;
    // ++ ohter genres you want to increment
}
if(答案==“1”){

非常感谢您对Beagle的回复。现在我唯一关心的是我的目标是让textArray元素随机化,所以我不一定知道要添加到哪种类型。我还希望“答案”保持为1和2。我意识到如果我要做“答案”每个DJ都有一个唯一的ID,比如x1,x2…可以工作,但我希望它对用户来说很简单。