Another Plinko program problem - error when input is not a number

I'm writing a Plinko game program and have pretty much finished everything, but there's one error that I can't fix. When option 2 or 3 (multiple chips in one slot or multiple chips in each slot) and then a character or string is inputted, it displays a proper error,resets the menu, displays an output error, and resets the menu again rather than only going back to the menu one after an error.

Here's my current code:
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;


const int PRIZE_SLOT_0 = 100;
const int PRIZE_SLOT_1 = 500;
const int PRIZE_SLOT_2 = 1000;
const int PRIZE_SLOT_3 = 0;
const int PRIZE_SLOT_4 = 10000;
const int PRIZE_SLOT_5 = 0;
const int PRIZE_SLOT_6 = 1000;
const int PRIZE_SLOT_7 = 500;
const int PRIZE_SLOT_8 = 100;


int reward (int chip_spot) {
    if (chip_spot == 0) {
        return PRIZE_SLOT_0;
    } else if (chip_spot == 1) {
        return PRIZE_SLOT_1;
    } else if (chip_spot == 2) {
        return PRIZE_SLOT_2;
    } else if (chip_spot == 3) {
        return PRIZE_SLOT_3;
    } else if (chip_spot == 4) {
        return PRIZE_SLOT_4;
    } else if (chip_spot == 5) {
        return PRIZE_SLOT_5;
    } else if (chip_spot == 6) {
        return PRIZE_SLOT_6;
    } else if (chip_spot == 7) {
        return PRIZE_SLOT_7;
    } else {
        return PRIZE_SLOT_8;
    }
}

int single_drop_simulator (int slot, int print_chip_spot) {
    double chip_spot = slot;
    for (int i = 0; i < 12; i++) {
        chip_spot += rand() % 2 ? .5: -.5;
        if (chip_spot > 8) {
            chip_spot -= 1.0;
        }
        if (chip_spot < 0) {
            chip_spot += 1.0;
        }
        if (print_chip_spot == 1) {
            cout << fixed << setprecision(1) << chip_spot << setw(4);
        }
    }
    return reward(chip_spot);
}


int multiple_drop_simulator(int number_of_chips, int slot) {
    double total_winnings = 0;
    for (int i = 0; i < number_of_chips; i++) {
       total_winnings += single_drop_simulator(slot, 0);
    }
    return total_winnings;
}

int main() {
    srand(time(NULL));
    double slot;
    bool end;
    do {
        
        //Menu
        cout << "\t\t\t\t** MENU **\nPlease choose one of the following operations:\n1 - Drop a single chip into one slot\n2 - Drop multiple chips into one slot\n3 - Drop multiple chips into each slot\n4 - Quit the program\n";
        int operation;
        cin >> operation;
        if(cin.fail()){
            cin.clear();
            cin.ignore(1000, '\n');
            cout << "Invalid selection. Please enter 1, 2, 3, or 4 to select one of the options.\n\n";
            end = false;
            continue;
        }
        if (operation > 4 || operation < 1) {
            cout << "Invalid selection. Please enter 1, 2, 3, or 4 to select one of the options.\n\n";
            end = false;
            continue;
        }
        
        //Single Chip
        if (operation == 1) {
            cout << "\n\t\t\t\t\t** DROP SINGLE CHIP **\nPlease enter the number of the slot to place Plinko chip (0-8):\n";
            cin >> slot;
            if(cin.fail()){
                cin.clear();
                cin.ignore(1000, '\n');
                cout << "Invalid selection. Please enter an integer from 0 to 8.\n\n";
                end = false;
                continue;
            }
            if (slot < 0 || slot > 8) {
                cout << "Invalid selection. Please enter an integer from 0 to 8.\n\n";
                end = false;
                continue;
            } else {
                cout << "Path: [";
                int winnings = single_drop_simulator(slot, 1);
                cout << "]\nYou won $" << winnings << "\n\n";
            }
            end = false;
            continue;
        }
        
        //Multiple Chips
        if (operation == 2) {
            cout << "\n\t\t  **DROP MULTIPLE CHIPS**\nPlease enter number of chips to be placed: ";
            int number_of_chips;
            cin >> number_of_chips;
            if (number_of_chips <= 0) {
                cout << "Invalid number. Please enter a positive integer > 0 for number of chips.\n\n";
                end = false;
                continue;
            }
            cout << "Please enter the number of the slot to place Plinko chip (0-8): ";
            cin >> slot;
            if(cin.fail()) {
                cin.ignore(1000, '\n');
                cout << "Invalid selection. Please enter an integer from 0 to 8.\n\n";
                end = false;
                continue;
            }
            if (slot < 0 || slot > 8) {
                cout << "Invalid selection. Please enter an integer from 0 to 8\n\n";
                end = false;
                continue;
            }
            double total_winnings = multiple_drop_simulator(number_of_chips, slot);
            cout << "You won $" << fixed << setprecision(2) << total_winnings;
            cout << "\nAverage amount earned per chip $" << fixed << setprecision(2) << total_winnings /  number_of_chips << "\n\n";
            end = false;
            continue;
        }
            if (operation == 3) {
            cout << "\n   **DROP MULTIPLE CHIPS IN EACH SLOT**\nPlease enter number of chips to be placed:\n";
            int number_of_chips;
            cin >> number_of_chips;
            if (number_of_chips <= 0) {
                cout << "Invalid number. Please enter a positive integer > 0 for number of chips.\n\n";
                end = false;
                continue;
            }
            double total_winnings = multiple_drop_simulator(number_of_chips, 0);
            cout << "The chips placed in slot 0 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 1);
            cout << "\n\nThe chips placed in slot 1 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 2);
            cout << "\n\nThe chips placed in slot 2 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 3);
            cout << "\n\nThe chips placed in slot 3 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 4);
            cout << "\n\nThe chips placed in slot 4 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 5);
            cout << "\n\nThe chips placed in slot 5 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 6);
            cout << "\n\nThe chips placed in slot 6 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 7);
            cout << "\n\nThe chips placed in slot 7 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips;
            total_winnings = multiple_drop_simulator(number_of_chips, 8);
            cout << "\n\nThe chips placed in slot 8 won a total of $" << fixed << setprecision(2) << total_winnings;
            cout << "\nThe average amount won by these chips was $" << fixed << setprecision(2) << total_winnings / number_of_chips << "\n\n";
            end = false;
            continue;
        }
        if (operation == 4){
            cout << "Goodbye!";
        }
        end = true;
    } while (end == false);
    return 0;
}


Thanks for the help!
Fixed it. I was just missing a cin.fail code in a necessary spot.
Topic archived. No new replies allowed.