Hello everybody. I am trying to make a basic slot machine program that generates three(3) random numbers when the "spin" is typed and entered, and ends when all three numbers equal five(5). Here is what I have so far:
Now, the problem I'm having is, it seems to end randomly, and you don't have to type "spin" to make the loop run. Could someone shed some light on the situation for a confused beginner? Thanks in advance for any and all advice.
Your loop condition does not do what you think it does.
It should look like this: while (myarray[0] != 5 && myarray[1] != 5 && myarray[2] !=5)
You should use a do-while loop since the spinning has to happen at least once. If accidentally all three elements of myarray is 5, then your program won't run.
cin >> a; will delete the contents of a and replace it with the next word what is typed in by the user. You should check for equality here :
1 2 3 4 5 6
//in your loop
string answer;
cin >> answer;
if (answer != "spin") {
//Do what you wanna do when not "spin" is entered.
}
The program still seems to end before all three arrays reach 5... Or is it just not showing that all three equal 5? Everything else seems to work fine though.