Array And Return Help



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  #include <map>
#include<string>
#include <iostream>

std::string Third();
std::string Ask();
std::string Ask2();
std::string WhoIsPicked3(std::string Nothing1, std::string Nothing2);

std::string ThirdRandomizer(std::string Picked1);
std::string ThirdDictionary();

std::string Third() {
	std::string Nothing = Ask();
	std::string TheNothing = Ask2();
	std::string Picked = WhoIsPicked3(Nothing, TheNothing);
	std::string Random = ThirdRandomizer(Picked);
	return Random;
}

std::string WhoIsPicked3(std::string Nothing1, std::string Nothing2) {

	if (Nothing1[0] == 'b' || Nothing1[0] == 'B' && Nothing1[1] == 'l' || Nothing1[1] == 'L') {
		std::string Nothing = "";
		Nothing1.append("Bloodhound");
	}
	else if (Nothing1[0] == 'g' || Nothing1[0] == 'G' && Nothing1[1] == 'i' || Nothing1[1] == 'I') {
		std::string Nothing1 = "";
		Nothing1.append("Gibraltar");
	}
	else if (Nothing1[0] == 'l' || Nothing1[0] == 'L' && Nothing1[1] == 'i' || Nothing1[1] == 'I') {
		std::string Nothing1 = "";
		Nothing1.append("Lifeline");
	}
	else if (Nothing1[0] == 'p' || Nothing1[0] == 'P' && Nothing1[1] == 'a' || Nothing1[1] == 'A') {
		std::string Nothing1 = "";
		Nothing1.append("Pathfinder");
	}
	else if (Nothing1[0] == 'w' || Nothing1[0] == 'W' && Nothing1[1] == 'r' || Nothing1[1] == 'R') {
		std::string Nothing1 = "";
		Nothing1.append("Wraith");
	}
	else if (Nothing1[0] == 'b' || Nothing1[0] == 'B' && Nothing1[1] == 'a' || Nothing1[1] == 'A') {
		std::string Nothing1 = "";
		Nothing1.append("Bangalore");
	}
	else if (Nothing1[0] == 'c' || Nothing1[0] == 'C' && Nothing1[1] == 'a' || Nothing1[1] == 'A') {
		std::string Nothing1 = "";
		Nothing1.append("Caustic");
	}
	else if (Nothing1[0] == 'm' || Nothing1[0] == 'M' && Nothing1[1] == 'i' || Nothing1[1] == 'I') {
		std::string Nothing1 = "";
		Nothing1.append("Mirage");
	}
	else {
		std::cout << "Incorrect answer try again.";
		WhoIsPicked3(Nothing1, Nothing2);
	}
	return Nothing1, Nothing2;
}
std::string ThirdRandomizer(std::string Picked1) {
	int a = 10;
	while (a == 10) {
		int SelectedLegend1 = rand() % 8;
		std::string LegendArray[] = { "Bloodhound","Gibraltar","Lifeline","Pathfinder","Wraith","Bangalore","Caustic","Mirage" };
		if (Picked1[0] == 'b' || Picked1[0] == 'B' && Picked1[1] == 'l' || Picked1[1] == 'L') {
			LegendArray[0] = "";
		}
		else if (Picked1[0] == 'g' || Picked1[0] == 'G' && Picked1[1] == 'i' || Picked1[1] == 'I') {
			LegendArray[1] = "";
		}
		else if (Picked1[0] == 'l' || Picked1[0] == 'L' && Picked1[1] == 'i' || Picked1[1] == 'I') {
			LegendArray[2] = "";
		}
		else if (Picked1[0] == 'p' || Picked1[0] == 'P' && Picked1[1] == 'a' || Picked1[1] == 'A') {
			LegendArray[3] = "";
		}
		else if (Picked1[0] == 'w' || Picked1[0] == 'W' && Picked1[1] == 'r' || Picked1[1] == 'R') {
			LegendArray[4] = "";
		}
		else if (Picked1[0] == 'b' || Picked1[0] == 'B' && Picked1[1] == 'a' || Picked1[1] == 'A') {
			LegendArray[5] = "";
		}
		else if (Picked1[0] == 'c' || Picked1[0] == 'C' && Picked1[1] == 'a' || Picked1[1] == 'A') {
			LegendArray[6] = "";
		}
		else if (Picked1[0] == 'm' || Picked1[0] == 'M' && Picked1[1] == 'i' || Picked1[1] == 'I') {
			LegendArray[7] = "";
		}
		if (LegendArray[SelectedLegend1] != "") {
			std::cout << LegendArray[SelectedLegend1];
			return LegendArray[SelectedLegend1];
			break;
		}
	}
}

std::string ThirdDictionary() {

	std::string TheThird = Third();
	std::map<std::string, std::string> Traits; // Define Dictionary

	Traits.insert(std::pair<std::string, std::string>("Bloodhound", "\n-Passive : See tracks left behind your foes.\n-Tactical : Reveal hidden enemies, traps, and clues throughtout structures in front of you.\n-Ultimate : Enhance Sense, moves faster and highlights prey."));
	Traits.insert(std::pair<std::string, std::string>("Gibraltar", "\n-Passive : Aiming deplays a gun shield that blocks incoming fire.\n-Tactical : Throw down a dome-shield that blocks attacks for 15 seconds.\n-Ultimate : Call in concentrated mortar strike on a marked position."));
	Traits.insert(std::pair<std::string, std::string>("Lifeline", "\n-Passive : Revive knocked down teamates faster while protected by a shield wall. Healing items are used 25% faster.\n-Tactical : Call your drone of compassion to automatically heal nearby teamates over time.\n-Ultimate : Care package with high quality defensive gear."));
	Traits.insert(std::pair<std::string, std::string>("Pathfinder", "\n-Passive : Scan a survey beacon to reveal the ring's next location.\n-Tactical: Grapple to get to out-of-reach places quickly.\n-Ultimate : Create a zipline for everyone to use"));
	Traits.insert(std::pair<std::string, std::string>("Wraith", "\n-Passive : A voice warns you when danger approaches. As far as you can tell, it's on your side.\n-Tactical : Reposition quickly through the safety of void space, avoiding all damage.\n-Ultimate : Link two locations with portals for 60 seconds, allowing your entire team to use them."));
	Traits.insert(std::pair<std::string, std::string>("Bangalore", "\n-Passive : Taking fire while sprinting makes you move faster for a brief time.\n-Tactical : Fire's a high-velocity smoke canister that explodes into a smoke wall on impact.\n-Ultimate : Call in an artillery strike that slowly creeps across the landscape."));
	Traits.insert(std::pair<std::string, std::string>("Caustic", "\n-Passive : Allows you to see enemies through your gas.\n-Tactical : Drop canisters that release deadly Nox gas when shot or triggered by enemies.\n-Ultimate : Blankets a large area in Nox gas."));
	Traits.insert(std::pair<std::string, std::string>("Mirage", "\n-Passive : Automatically drop a decoy and cloak for five seconds when knocked down.\n-Tactical : Send out a holographic decoy to confuse the enemy.\n-Ultimate : Deploy a team of Decoys to distract enemies while you cloak."));
	
	std::string Legend = Traits.find(TheThird)->second;
	std::cout << Legend << "\n\n";
	system("PAUSE");
	return Legend;
}

std::string Ask() {
	std::string Nothing = "";
	std::cout << "1st Legend already picked?: ";
	std::getline(std::cin, Nothing);
	std::cout << std::endl;
	return Nothing;
}

std::string Ask2() {
	std::string Nothing = "";
	std::cout << "2nd Legend already picked?: ";
	std::getline(std::cin, Nothing);
	std::cout << std::endl;
	return Nothing;
}


For Example, if I run the program and say "Bangalore" as first and "Wraith" as second I need the Array to be { "Bloodhound","Gibraltar","Lifeline","Pathfinder","","","Caustic","Mirage" };
so I can test if LegendArray[SelectedLegend1] != "". But I run into one problem, how do I get the return values from WhoIsPicked3(); to ThirdRandomizer(); P.S. Picked1 is the return values of WhoIsPicked3(); as stated from Third();

More information on understanding my question, how do I set 2 arguments for 2 returns?

Current Output of Array: If I do "Bangalore" First and "Wraith" Second I get : {"Bloodhound", "Gibraltar", "Lifeline", "Pathfinder", "", "Bangalore", "Caustic", "Mirage"};

Probably because the if statements in WhoIsPicked3() are replacing it?
Last edited on
There's no main() to run your program and variables name such as 'Nothing', 'Nothing1' and 'Nothing2' are hard to interpret.
Could you please describe what you aim to do or provide us code enough to work it out by ourselves?

Anyway, please let us know if the following code could be od any inspiration:

Majeek.dat:
Bloodhound
-Passive : See tracks left behind your foes.\n-Tactical : Reveal hidden enemies, traps, and clues throughtout structures in front of you.\n-Ultimate : Enhance Sense, moves faster and highlights prey.
Gibraltar
-Passive : Aiming deplays a gun shield that blocks incoming fire.\n-Tactical : Throw down a dome-shield that blocks attacks for 15 seconds.\n-Ultimate : Call in concentrated mortar strike on a marked position.
Lifeline
-Passive : Revive knocked down teamates faster while protected by a shield wall. Healing items are used 25% faster.\n-Tactical : Call your drone of compassion to automatically heal nearby teamates over time.\n-Ultimate : Care package with high quality defensive gear.
Pathfinder
-Passive : Scan a survey beacon to reveal the ring's next location.\n-Tactical: Grapple to get to out-of-reach places quickly.\n-Ultimate : Create a zipline for everyone to use
Wraith
-Passive : A voice warns you when danger approaches. As far as you can tell, it's on your side.\n-Tactical : Reposition quickly through the safety of void space, avoiding all damage.\n-Ultimate : Link two locations with portals for 60 seconds, allowing your entire team to use them.
Bangalore
-Passive : Taking fire while sprinting makes you move faster for a brief time.\n-Tactical : Fire's a high-velocity smoke canister that explodes into a smoke wall on impact.\n-Ultimate : Call in an artillery strike that slowly creeps across the landscape.
Caustic
-Passive : Allows you to see enemies through your gas.\n-Tactical : Drop canisters that release deadly Nox gas when shot or triggered by enemies.\n-Ultimate : Blankets a large area in Nox gas.
Mirage
-Passive : Automatically drop a decoy and cloak for five seconds when knocked down.\n-Tactical : Send out a holographic decoy to confuse the enemy.\n-Ultimate : Deploy a team of Decoys to distract enemies while you cloak.


main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <cctype>
#include <iostream>
#include <fstream>
#include <map>
#include <string>


using w_texts = std::map<std::string, std::string>;


w_texts createMapFromFile(std::string fname);

std::string turnSlashNIntoNewlines(std::string& line);

std::map<char, std::string> createMapFromMap(const w_texts& mymap);

std::string askDumbQuestion(const std::map<char, std::string>& options);

void printDetails(const w_texts& texts, std::string mykey);


int main()
{
    auto mymap { createMapFromFile("Majeek.dat") };
    auto c_word { createMapFromMap(mymap) };
    printDetails(mymap, askDumbQuestion(c_word));
}


w_texts createMapFromFile(std::string fname)
{
    std::ifstream fin(fname);
    if(!fin) {
        std::cout << "Cannot open " << fname << ".\n";
        return w_texts();
    }

    bool is_key { true };
    w_texts mymap;
    std::pair<std::string, std::string> tmp_pair;
    for (std::string line;  std::getline(fin, line); /**/) {
        if(is_key) {
            tmp_pair.first = line;
        } else {
            turnSlashNIntoNewlines(line);
            tmp_pair.second = line;
            mymap.insert(tmp_pair);
        }
        is_key = !is_key;
    }
    return mymap;
}


std::string turnSlashNIntoNewlines(std::string& line)
{
    try {
        for(std::string::size_type pos {}; /**/; ++pos) {
            line.replace(line.find("\\n", pos), 2, "\n");
        }
    } catch (std::exception&) {
        // no replacement done or no more replacement needed
    }
    return line;
}


std::map<char, std::string> createMapFromMap(const w_texts& mymap)
{
    std::map<char, std::string> c_to_word;
    for (const auto& e : mymap) {
        c_to_word.emplace(std::tolower(e.first.at(0)), e.first);
    }
    return c_to_word;
}


std::string askDumbQuestion(const std::map<char, std::string>& options)
{
    for (std::string line; /**/ ; /**/) {
        std::cout << "What details do you want to read of?\n";
        for (const auto& p : options) {
            std::cout << p.first << ") " << p.second << '\n';
        }
        std::cout << ">>> ";
        std::getline(std::cin, line);
        char c { static_cast<char>(std::tolower(line.at(0))) };
        if(options.find(c) != options.end()) {
            return options.at(c);
        } else {
            std::cout << "Unknown option '" << c << "'. Please try again.\n";
        }
    }
}


void printDetails(const w_texts& texts, std::string mykey)
{
    std::cout << "Here are your details for " << mykey << ":\n"
              << texts.at(mykey) << '\n';
}

Topic archived. No new replies allowed.