vector problem

I want to make a hacking simulation. The first "mission" requires you to put 3 words in the right order, but when I do put the words in the right order, the game displays the correct message, "Welcome back, Jordan!", but then displays the text to type the three words again. How can i fix this. Mainly to go into a new function when someone gets it correct.
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
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<string>hackno;
int knowledge = 10;
int tries = knowledge -= 5;
int totaltries;
void firstMission();

int main()
{
	cout << "\t\tHacker Simulator\n\n";
	cout << "Your knowledge level: " << knowledge << "\n\n";
	firstMission();
	return 0;
}

void firstMission()
{
	string guess1, guess2, guess3;
	
	hackno.push_back("million");
	hackno.push_back("pc");
	hackno.push_back("hack");

	cout << "\n\t\tFirst Mission\n\n";
	cout << "Put the three words together to get into this bank account\n";
	cout << "1.hack 2.million 3.pc";
	do
	{
		cout << "\nEnter the first word: ";
		cin >> guess1;

		cout << "\nEnter the second word: ";
		cin >> guess2;

		cout << "\nEnter the third word: ";
		cin >> guess3;

		if (guess1 == hackno[0], guess2 == hackno[1], guess3 == hackno[2])
		{
			cout << "\n\n\t\tWelcome again, Jordan!\n\n";
		}
		else
		{
			totaltries += 1;
		}
	} while (totaltries <= tries);
}
Last edited on
add a break; after line 45
line 43 does not do what you want... it only checks guess3.

If you want all of those conditions to have to be true, then you want the && operator:

 
if (guess1 == hackno[0] && guess2 == hackno[1] && guess3 == hackno[2])
Topic archived. No new replies allowed.