Plinko with Functions

the program is broken basically into 3 parts.
A - dropping 1 token in the plinko machine and show your winnings
B - dropping multiple tokens in the same slot of the plinko machine then report the total average $ of those tokens.
C - Exit the program

Basically The program works but now I am trying to simplify it by combining part A and part B into a single function. I already have A in a function but I am confused on how to implement part B into a function. I am a noob but any help would be great!













#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>


using namespace std;

//............................................................................................. FUNCTIONS...................
int prize_Slot_Chip (int winPrice)
{
int amont_Money = 0;
do{

if (winPrice == 0){ amont_Money = 100;}// cout << "You won 100!" << endl;}
else if (winPrice == 1){ amont_Money = 500;} //cout << "You won 500!" << endl;}
else if (winPrice == 2){ amont_Money = 1000;}// cout << "You won 1000!" << endl;}
else if (winPrice == 3){ amont_Money = 0; }//cout << "You won 0!" << endl;}
else if (winPrice == 4){ amont_Money = 10000; }//cout << "You won 10000!" << endl;}
else if (winPrice == 5){ amont_Money = 0; }//cout << "You won 0!" << endl;}
else if (winPrice == 6){ amont_Money = 1000; }//cout << "You won 1000!"<<endl;}
else if (winPrice == 7){ amont_Money = 500;}// cout //<< "You won 500!" << endl;}
else if (winPrice == 8){ amont_Money = 100;} //cout << "You won 100!" << endl;}


} while (winPrice < 0 && winPrice > 8);
return amont_Money;
}

//..........................................................................................................................
int setting_Chip_Slot (double chip_Location)
{
double move;
int leftRigth = 0;
move = chip_Location;
if (chip_Location < 0 || chip_Location >= 9){
cout << "Invalid Number! Try between the range (1 and 8)" << endl;
} else {
for (int i=0; i<12; i++)
{


leftRigth = rand() % 2;
if (leftRigth == 0)
{
move = move-.5; //moves to the left
if(move < 0)
{
move = move + 1;// if the position goes out of range
}
}
else
{
move = move + .5; // moves to the right
if (move > 8)
{
move = move -1;
}
}
//cout<< move <<endl;

}
return move;

}
}
//............................................................................................ MAIN ...........................
int main()
{
srand (time(0));
int n = 0, num = 0, last_input = 0;
char input; //the option the user choose
bool put0= false;
double one_Chip = 0, money_Won = 0, ave = 0.0, total = 0.0;
//----------------Part 1-------------------------------------------------------------------------

do{
system("cls");

cout << "\n PLINKO Main Menu\n";
cout << "\nDrop one chip into one slot (1):\n";
cout << "\nDrop multiple chips into one slot (2):\n";
cout <<"\nEnter one number, which is the number of chips to drop into every slot (3): \n"<<endl;
cout << "\nQuit (Q).\n"; cin >> input;
switch(input){
//.........................................................................................................
case '1':
system("cls");
cout << "Where would you like to place your chip?:\t " << endl;
cout << "\n\t0\t1\t2\t3\t4\t5\t6\t7\t8: ";
cin >> n;
one_Chip = setting_Chip_Slot (n);
money_Won = prize_Slot_Chip (one_Chip);
cout << "The amount of money for that chip is: " <<money_Won << endl;
cout << "The location of the chip as it falls: "<< one_Chip << endl;
system("pause");
//return 0;
break;
//.........................................................................................................
case'2': //THIS IS THE PART WHERE I NEED HELP, I NEED TO ADD ALL THIS INFORMATION BELOW INTO A FUNCTION AND I DO NOT KNOW HOW. THANK YOU!!!

system("cls");
cout << "\n How many chips would you like to drop?\t ";
cin >>num;
cout << "\nChoose your slot"<< endl;
cout << "\n\t0\t1\t2\t3\t4\t5\t6\t7\t8: ";
cin >> n;
if (num > 0){
double sum = 0.0, average = 0.0;
{
for (double i = 0; i < num; i++)
{
double setting_Chip = setting_Chip_Slot (n);
double prize = prize_Slot_Chip (setting_Chip);
sum = sum + prize ;
average = sum / num;
}

cout << "Your total is : $ " << sum << endl;
cout << "Your average is: " << average << endl;

}

system("pause");
//return 0;
break;
}
//............................................................................................................................................
case'3':
system("cls");
cout << "Enter a number of chips to drop into every slot ";
cin>> last_input;
if (last_input > 0){
double last_Sum = 0, last_Average = 0, last_Prize = 0;

for (int i = 0; i < 9; i++)
{
last_Sum = 0;
for( int j = 0; j <= last_input; j++)
{

double setting_Chip = setting_Chip_Slot (i);
double last_Prize = prize_Slot_Chip (setting_Chip);
last_Sum = last_Sum + last_Prize;

}
last_Average = last_Sum / last_input;
cout << "Slot " << i << endl;
cout << " Average: " << last_Average << endl;
cout << "Total $: " << last_Sum << endl;
}
system("pause");
//return 0;
break;
}

case 'Q': case'q':
put0 = true;
cin.clear();
break;

}
while(put0 == false){
cin.get();
cin.clear();

//return 0 ;
break;
}



} while(put0 == false);
cin.get();
cin.clear();
return 0;
}
Topic archived. No new replies allowed.