Get values to match for certain output

Hi guys I'm having trouble getting the output from my calculate function, I'm trying to get the middle row (val4, val5, val6) to always output three in a row. However, eventhough it is three in a row when the numbers are outputted, within the function -- the numbers actually don't match so is there a workaround? Thanks in advance.


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
133
134
135
136
137
138
139
140
141
142
143
#include <cstdlib>
#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>
using namespace std;

void set1(int &num1, string symbol1, string symbol2)
{
	num1 = rand() % 11 + 1;
	if ((num1 == 1) || (num1 == 2))
	{
		cout << setw(10) << symbol1;
	}
	else if (num1 == 3)
	{
		cout << setw(10) << symbol2;
	}
	else if ((num1 == 4) || (num1 == 5))
	{
		cout << setw(10) << "A";
	}
	else if ((num1 == 6) || (num1 == 7))
	{
		cout << setw(10) << "X";
	}
	else if ((num1 == 8) || (num1 == 9))
	{
		cout << setw(10) << "O";
	}
	else if ((num1 == 10) || (num1 == 11))
	{
		cout << setw(10) << "3";
	}
}

void set2(int &num2, string cherry, string wild)
{
	num2 = rand() % 11 + 1;
	if ((num2 == 1) || (num2 == 2))
	{
		cout << setw(2) << cherry;
	}
	else if (num2 == 3)
	{
		cout << setw(2) << wild;
	}
	else if ((num2 == 4) || (num2 == 5))
	{
		cout << setw(2) << "A";
	}
	else if ((num2 == 6) || (num2 == 7))
	{
		cout << setw(2) << "X";
	}
	else if ((num2 == 8) || (num2 == 9))
	{
		cout << setw(2) << "O";
	}
	else if ((num2 == 10) || (num2 == 11))
	{
		cout << setw(2) << "3";
	}
}
void set3(int &num3, string cherry, string wild)
{
	num3 = rand() % 11 + 1;
	if ((num3 == 1) || (num3 == 2))
	{
		cout << setw(2) << cherry << endl;
	}
	else if (num3 == 3)
	{
		cout << setw(2) << wild << endl;
	}
	else if ((num3 == 4) || (num3 == 5))
	{
		cout << setw(2) << "A" << endl;
	}
	else if ((num3 == 6) || (num3 == 7))
	{
		cout << setw(2) << "X" << endl;
	}
	else if ((num3 == 8) || (num3 == 9))
	{
		cout << setw(2) << "O" << endl;
	}
	else if ((num3 == 10) || (num3 == 11))
	{
		cout << setw(2) << "3" << endl;
	}
}

void calculate(int num1, int num2, int num3, string cherry, string wild)
{
	if ((num1 == num2 && num1 == num3) || (num2 == num1 && num2 == num3) || (num3 == num1 && num3 == num2))
	{
		cout << "you won three in a row!" << endl;
	}
		
}

int main()
{
	string mainMenu;
	do
	{
		cout << "Lets play slot machine!" << endl;

		int val1, val2, val3, val4, val5, val6, val7, val8, val9;
		srand(time(0));
		int user1 = 0;
		string menuInput;
		string cherry = "C";
		string wild = "W";

		//row1 = rand() % 9 + 1;
		//row2 = rand() % 9 + 1;
		//row3 = rand() % 9 + 1;
		//column1 = rand() % 9 + 1;
		//column2 = rand() % 9 + 1;
		//column3 = rand() % 9 + 1;

		set1(val1, cherry, wild);
		set2(val2, cherry, wild);
		set3(val3, cherry, wild);
		set1(val4, cherry, wild);
		set2(val5, cherry, wild);
		set3(val6, cherry, wild);
		set1(val7, cherry, wild);
		set2(val8, cherry, wild);
		set3(val9, cherry, wild);

		calculate(val4, val5, val6, cherry, wild);


		cout << "Would you like to go to keep playing? y/n: ";
		cin >> mainMenu;
	} while (tolower(mainMenu[0]) == 'y');
	

	return 0;
}
Last edited on
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Topic archived. No new replies allowed.