Need help with plinko

I'm supposed to make a plinko simulator for my class. I've been working on it, but for some reason the random number generator doesn't seem to work. When I run the program it prints 7.5 12 times and doesnt move the plinko chip at all. Also, my menu wont quit when I press C like it should, it just prints that it is an invalid entry. Please help me! Thank you.

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
144
145
146
147
148
149
150
151
152
#include "stdafx.h"
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>

using namespace std;

//VARIABLES
string menu_input;
int slot;
double slot_position;
int random;

const double slot0 = 0;
const double slot1 = 1;
const double slot2 = 2;
const double slot3 = 3;
const double slot4 = 4;
const double slot5 = 5;
const double slot6 = 6;
const double slot7 = 7;
const double slot8 = 8;

const double money1 = 100;
const double money2 = 500;
const double money3 = 1000;
const double money4 = 0;
const double money5 = 10000;





// PART 1- THE MENU
void menu() {
	cout << "\t\t\tPLINKO SIMULATOR" << endl;
	cout << "\tPlease select one of the following options: \n" << endl;
	cout << "Drop one chip into one slot \t\t\t (Enter A)" << endl;
	cout << "Drop multiple chips into one slot \t\t (Enter B)" << endl;
	cout << "Quit \t\t\t\t\t\t (Enter C)\n" << endl;
	cin >> menu_input;
}

void positionfinder() {
	for (int i = 1; i < 13; i++) {
		if (slot_position > 0 && slot_position < 8) {
			random = rand() % 2;
			if (random = 0) {
				slot_position = slot_position + .5;
			}
			if (random = 1) {
				slot_position = slot_position - .5;
			}
		}
		if (slot_position = 0) {
			slot_position = slot_position + .5;
		}
		else if (slot_position = 8) {
			slot_position = slot_position - .5;
		}
		cout << slot_position << endl;
	}
	cout << "The final position is: " << slot_position << endl;
	
	if (slot_position == slot0 || slot_position == slot8) {
		cout << "You win $" << money1 << endl;
	}
	if (slot_position == slot1 || slot_position == slot7) {
		cout << "You win $" << money2 << endl;
	}
	if (slot_position == slot2 || slot_position == slot6) {
		cout << "You win $" << money3 << endl;
	}
	if (slot_position == slot3 || slot_position == slot5) {
		cout << "You win $" << money4 << endl;
	}
	if (slot_position == slot4) {
		cout << "You win $" << money5 << endl;
	}
	cout << "\nReturning to menu...\n" << endl;
	//positionfinder is not working. It still spits out '7.5' 12 times for everything. The money thing doesnt even work because 7.5 isnt supposed to be one of the final values
}

int main() {
	srand(time(0));	

	//PART 2- LET THE CHIPS FALL
	while (menu_input != "C" || menu_input != "c") {
		menu();		
		// it registers c as invalid
		//when it registers something as invalid, when I try to type anything it  no longer registers anything as valid
		if (menu_input == "A" || menu_input == "a") {
			cout << "\n\nWhich slot would you like to drop your chip?" << endl;
			cout << "(Select an integer from 0-8)" << endl;
			cin >> slot;			
			if (slot == 0) {
				slot_position = slot0;
				positionfinder();				
			}
			else if (slot == 1) {
				slot_position = slot1;
				positionfinder();
			}
			else if (slot == 2) {
				slot_position = slot2;
				positionfinder();
			}
			else if (slot == 3) {
				slot_position = slot3;
				positionfinder();
			}
			else if (slot == 4) {
				slot_position = slot4;
				positionfinder();
			}
			else if (slot == 5) {
				slot_position = slot5;
				positionfinder();
			}
			else if (slot == 6) {
				slot_position = slot6;
				positionfinder();
			}
			else if (slot == 7) {
				slot_position = slot7;
				positionfinder();
			}
			else if (slot == 8) {
				slot_position = slot8;
				positionfinder();
			}
			else if (slot < 0 || slot > 8) {
				cout << "\n\nInvalid Entry.\n" << endl;
				cout << "Returning to menu...\n" << endl;
			}				
		}		
		//still need to put option b in here
		else if (menu_input != "A" || menu_input != "a" || menu_input != "B" || menu_input != "b" || menu_input != "C" || menu_input != "c") {
			cout << "\n\nInvalid Entry." << endl;
			cout << "\nReturning to menu...\n" << endl;
			//it always registers c and b as invalid
		}
	}	
	if (menu_input == "C" || menu_input == "c") {
		cout << "Good Bye!" << endl;
		//DOES NOT WORK
	}
	system("pause");
	return 0;
}
Lines 49, 52, 56 and 59 all use assignment in an if condition. Is that really what you intend?
Last edited on
Topic archived. No new replies allowed.