INVALID SLOT
I need to make an "INVALID SLOT" show up when a wrong input is entered in the single drop and multiple drop
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
|
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <iomanip>
using namespace std;
int main()
{
int menu = 1;
cout << "Welcome to Plinko!" << endl;
while (menu != 3)
{
cout << endl;
cout << "MENU: Please select one of the following options: \n 1 - Drop a single chip into one slot \n 2 - Drop multiple chips into one slot \n 3 - Quit the program \n";
cout << "Enter your selection now: ";
string option = "";
cin >> option;
int slotnumber = 0;
int numberOfChips = 0;
double location = slotnumber;
double reward = 0;
srand(time(0));
const double PRIZE_0 = 100;
const double PRIZE_1 = 500;
const double PRIZE_2 = 1000;
const double PRIZE_3 = 0;
const double PRIZE_4 = 1000;
const double PRIZE_5 = 0;
const double PRIZE_6 = 1000;
const double PRIZE_7 = 500;
const double PRIZE_8 = 100;
if (option != "1" && option != "2" && option != "3")
{
cout << "INVALID SELECTION. Please enter 1, 2 or 3";
cout << endl;
}
if (option == "1")
{
cout << endl << endl;
cout << "*** DROP SINGLE CHIP ***" << endl;
cout << "Which slot do you want to drop the chip in (0-8)?: ";
cin >> slotnumber;
if (slotnumber >= 0 && slotnumber <= 8)
{
double location = slotnumber;
cout << endl;
cout << "*** DROPPING CHIP INTO SLOT " << slotnumber << " ***" << endl;
cout << "Path: "<< "[" << location << " ";
for (int i = 0; i < 12; i++)
{
double random = rand() % 2;
if (random < 1)
{
location = location + 0.5;
}
else
{
location = location - 0.5;
}
if (location < 0)
{
location = 0.5;
}
else if (location > 8)
{
location = 7.5;
}
cout << location << " ";
if (i < 12)
{
cout << location;
}
}
if (location == 0) { reward = PRIZE_0; }
else if (location == 1) { reward = PRIZE_1; }
else if (location == 2) { reward = PRIZE_2; }
else if (location == 3) { reward = PRIZE_3; }
else if (location == 4) { reward = PRIZE_4; }
else if (location == 5) { reward = PRIZE_5; }
else if (location == 6) { reward = PRIZE_6; }
else if (location == 7) { reward = PRIZE_7; }
else if (location == 8) { reward = PRIZE_8; }
cout << "]";
}
cout << endl;
cout << fixed << setprecision(2) << "Winnings: $" << reward << endl;
cout << endl << endl;
}
else if (option == "2")
{
cout << endl << endl;
cout << "*** DROP MULTIPLE CHIPS ***" << endl;
cout << "How many chips do you want to drop ( >0)? ";
cin >> numberOfChips;
if (numberOfChips > 0)
{
cout << "Which slot do you want to drop the chip in (0-8)? ";
cin >> slotnumber;
if (slotnumber >= 0 && slotnumber <= 8)
{
double location = slotnumber;
double totalWinnings = 0;
for (int i = 0; i < 12; i++)
{
totalWinnings = totalWinnings + reward;
for (int i = 0; i < 12; i++)
{
double random = rand() % 2;
if (random < 1)
{
location = location + 0.5;
}
else
{
location = location - 0.5;
}
if (location < 0)
{
location = 0.5;
}
else if (location > 8)
{
location = 7.5;
}
}
if (location == 0){ reward = 100; }
else if (location == 1){ reward = 500; }
else if (location == 2){ reward = 1000; }
else if (location == 3){ reward = 0; }
else if (location == 4){ reward = 1000; }
else if (location == 5){ reward = 0; }
else if (location == 6){ reward = 1000; }
else if (location == 7){ reward = 500; }
else if (location == 8){ reward = 100; }
location = slotnumber;
}
double average = totalWinnings / numberOfChips;
cout << fixed << setprecision(2) << "Total winnings on " << numberOfChips << " chips: $" << totalWinnings << endl;
cout << fixed << setprecision(2) << "Average winnings per chip: $" << average << endl;
}
}
}
else if (option == "3")
{
cout << "GOODBYE!" << endl;
system("pause");
return 0;
}
}
system("pause");
return 0;
}
|
Topic archived. No new replies allowed.