Question on my c++ project (loop)

I am almost done with my project, but this one minor thing is keep bothering me.
I have to find the total value of winning chips.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <iomanip>

using namespace std;



int main() {
int userInput;
int numberOfChips;
int dropofChips;

const int BOARD_ROWS = 12;

double currentSlot = 0.0;
double moveDirection = 0.0;
double slotNumber = 0.0;
double reward = 0.0;
double rewardTotal = 0.0;
double rewardAverage = 0.0;

const double REWARD_0 = 100.00;
const double REWARD_1 = 500.00;
const double REWARD_2 = 1000.00;
const double REWARD_3 = 0.00;
const double REWARD_4 = 10000.00;
const double REWARD_5 = 0.00;
const double REWARD_6 = 1000.00;
const double REWARD_7 = 500.00;
const double REWARD_8 = 100.00;

const double CHIP_SHIFT = 0.5;

srand(42);

cout << "Welcome to the Plinko simulator!" << endl << endl;

while (true)
{
cout << "Menu: Please select one of the following options:" << endl << endl;
cout << "0 - Quit the program" << endl;
cout << "1 - Drop a single chip into one slot" << endl;
cout << "2 - Drop multiple chips into one slot" << endl << endl;
cout << "Enter your selection now: ";
cin >> userInput;
cout << endl;

if (userInput < 0 || userInput > 2) {
cout << "Invalid selection. Please enter 0, 1 or 2" << endl << endl;
}
else {
if (userInput == 0) {
cout << "Goodbye!";
return 0;
}

else if (userInput == 1)
{
cout << "*** Drop a single chip ***" << endl << endl;
cout << "Which slot do you want to drop the chip in (0-8)? ";
cin >> slotNumber;
cout << endl;

if (slotNumber >= 0 && slotNumber <= 8) {
cout << "*** Dropping chip into slot " << static_cast<int>(slotNumber) << " ***" << endl;;
cout << "Path: [";
cout << fixed << setprecision(1) << slotNumber << " ";
currentSlot = slotNumber;
for (int i = 0; i < BOARD_ROWS; ++i) {
if (currentSlot == 8) {
currentSlot = currentSlot - CHIP_SHIFT;
}
else if (currentSlot == 0) {
currentSlot = currentSlot + CHIP_SHIFT;
}
else {
moveDirection = rand() % 2;
if (moveDirection == 0) {
currentSlot = currentSlot - CHIP_SHIFT;
}
else
{
currentSlot = currentSlot + CHIP_SHIFT;
}
}
cout << fixed << setprecision(1) << currentSlot;

if (i < BOARD_ROWS - 1) {
cout << " ";
}
else {
cout << "]" << endl;
}
}

if (currentSlot == 0)
{
reward = REWARD_0;
}
else if (currentSlot == 1) {
reward = REWARD_1;
}
else if (currentSlot == 2) {
reward = REWARD_2;
}
if (currentSlot == 3) {
reward = REWARD_3;
}
else if (currentSlot == 4) {
reward = REWARD_4;
}
else if (currentSlot == 5) {
reward = REWARD_5;
}
else if (currentSlot == 6) {
reward = REWARD_6;
}
else if (currentSlot == 7) {
reward = REWARD_7;
}
else if (currentSlot == 8) {
reward = REWARD_8;
}
cout << "Winnings: $" << fixed << setprecision(2) << reward << endl << endl;
}
else {
cout << "Invalid slot." << endl << endl;
}
}

else if (userInput == 2)
{
cout << "*** Drop multiple chips ***" << endl << endl;
cout << "How many chips do you want to drop (>0)? ";
cin >> numberOfChips;
cout << endl;

if (numberOfChips <= 0) {
cout << "Invalid number of chips." << endl;
}
else {
cout << "Which slot do you want to drop the chip in (0-8)? ";
cin >> dropofChips;
cout << endl;
if (dropofChips >= 0 && dropofChips <= 8) {
currentSlot = slotNumber;
for (int i = 0; i < BOARD_ROWS; ++i)
{
if (currentSlot == 8) {
currentSlot = currentSlot - CHIP_SHIFT;
}

else if (currentSlot == 0) {
currentSlot = currentSlot + CHIP_SHIFT;
}
else {
moveDirection = rand() % 2;
if (moveDirection == 0) {
currentSlot = currentSlot - CHIP_SHIFT;
}
else {
currentSlot = currentSlot + CHIP_SHIFT;
}
}
}

if (currentSlot == 0)
{
reward = REWARD_0;
}
else if (currentSlot == 1) {
reward = REWARD_1;
}
else if (currentSlot == 2) {
reward = REWARD_2;
}
else if (currentSlot == 3) {
reward = REWARD_3;
}
else if (currentSlot == 4) {
reward = REWARD_4;
}
else if (currentSlot == 5) {
reward = REWARD_5;
}
else if (currentSlot == 6) {
reward = REWARD_6;
}
else if (currentSlot == 7) {
reward = REWARD_7;
}
else if (currentSlot == 8) {
reward = REWARD_8;
}


rewardTotal = reward + rewardTotal;
cout << "Total winnings on " << fixed << setprecision(2) << numberOfChips << " chips: ";
cout << rewardTotal << endl;

rewardAverage = rewardTotal / numberOfChips;
cout << "Average winnings per chip: " << fixed << setprecision(2) << rewardAverage;
cout << endl << endl;


}

else {
cout << "Invalid slot." << endl << endl;
}
}
}
}
}
//system("pause");
return 0;
}


For multiple slot, if I put 142 chips and slot 7, I am expecting to have 155700.00. But, I am not even close to get that number. Could you englighten me what I have to do?
Last edited on
rewardTotal = reward + rewardTotal; looks correct for the grand total.

if you want only positive values in a new total...

if(reward > 0)
postotal += reward;

Topic archived. No new replies allowed.