Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <ctime>
- #include <iomanip>
- #include <stdlib.h>
- using namespace std;
- string deal, choice, boxToKeep;
- const int n = 22;
- vector<int>sumTable;
- vector<double>boxes;
- vector<double>money;
- double values[n] = {0.01, 0.1, 0.5, 1, 5, 10, 50, 100, 250, 500, 750, 1000,
- 3000, 5000, 10000, 15000, 20000, 35000, 50000, 75000, 100000, 250000};
- double bottomFive[5], top[5], medium[10];
- int selected[n] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- double amount = 0.00, totAmount = 0.00;
- int bottoF = 0, topF = 0, mediumT = 0, firstRound, secondRound, thirdRound, fourthRound, fifthRound, sixthRound, gCount = 0, val, new_val = 1, sum = 0, total = 0, nextRound = 1, offer = 0, picked=0;
- void printBoxes()
- {
- for(int i = 0; i<n; i++)
- {
- if(i>0 && (i%3 == 0))
- cout << setw(7) << (sumTable[i]+1) << endl;
- else if(i >= 0)
- cout << setw(7) << (sumTable[i]+1);
- }
- }
- int wantToDeal()
- {
- if(total != 0)
- {
- cout << "\n\nDo you want to make a Deal or No Deal?\nType either Deal, or No Deal for your choice: ";
- getline(cin, deal);
- for(int i = 0; i<=(int)deal.size(); i++)
- {
- if(deal[i] == ' ')
- deal.erase(i, 1);
- else if(deal.size() > 1)
- deal.erase(deal.size()-1, 1);
- }
- if(deal[0] == 'D' || deal[0] == 'd' || sixthRound == 0)
- {
- nextRound = 0;
- }
- if(deal == "N" || deal == "n")
- {
- // do nothing
- }
- }
- return nextRound;
- }
- void traverse()
- {
- for(int i = 0; i<(int)money.size(); i++)
- {
- for(int j=0; j<(int)money.size(); j++)
- {
- if(money[i] == bottomFive[j])
- bottoF++;
- if(money[i] == medium[j])
- mediumT++;
- if(money[i] == top[j])
- topF++;
- };
- }
- }
- int bankersOffer()
- {
- traverse();
- totAmount -= amount;
- offer = 0.05 * (totAmount);
- return offer;
- }
- int main()
- {
- totAmount = 0;
- for(int i = 0; i<n; i++)
- totAmount += values[i];
- for(int i = 0, j = 21; i<5; i++, j--)
- {
- bottomFive[i] = values[i];
- top[j] = values[j];
- }
- for(int i = 0; i<n; i++)
- selected[i] = 0;
- for(int i = 7; i<17; i++)
- {
- medium[i] = values[i];
- }
- firstRound = secondRound = thirdRound = fourthRound = fifthRound = sixthRound = 1, gCount = 0;
- for(int i=0; i<n; i++)
- {
- sumTable.push_back(-1);
- }
- srand((unsigned)time(NULL));
- sum = rand()%n;
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- // check if number is used, making an array for used numbers
- while(sum == sumTable[j])
- {
- sum = rand()%n;
- j = 0;
- }
- }
- sumTable[i] = sum;
- sum = rand()%n;
- }
- printBoxes();
- cout << endl << endl;
- for(int i=0; i<n; i++)
- {
- boxes.push_back(values[sumTable[i]]);
- }
- /* for(int i=0; i<n; i++)
- {
- cout << setw(3) << boxes[i] << endl;
- }
- */
- while(!picked)
- {
- cout << "Please choose a box that you want to keep: ";
- getline(cin, boxToKeep);
- for(int i = 0; i<(int)boxToKeep.size(); i++)
- {
- val = atoi(boxToKeep.c_str());
- if(selected[val-1] == 0 && (val >= 1 && val <= 22) )
- {
- selected[val-1] = 1;
- cout << "\nYou have chosen box number " << val /*<< " which contains " << boxes[val-1]<< ".\n\n"*/ << endl << endl;
- picked = 1;
- }
- else
- {
- // ask over again
- }
- }
- }
- while(nextRound)
- {
- while(firstRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 5)
- {
- firstRound = 0;
- cout << "\nFirst round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- cout << "\n\nThe banker offers you " << bankersOffer() << ".\n\n";
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- amount = gCount = 0;
- while(secondRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 3)
- {
- secondRound = 0;
- cout << "\nSecond round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- bankersOffer();
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- amount = gCount = 0;
- while(thirdRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 3)
- {
- thirdRound = 0;
- cout << "\nThird round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- bankersOffer();
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- amount = gCount = 0;
- while(fourthRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 3)
- {
- fourthRound = 0;
- cout << "\nFourth round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- bankersOffer();
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- amount = gCount = 0;
- while(fifthRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 3)
- {
- fifthRound = 0;
- cout << "\nFifth round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- bankersOffer();
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- amount = gCount = 0;
- while(sixthRound && nextRound)
- {
- cout << "Please choose a box from 1 - 22 to open, and then press Enter: ";
- getline(cin, choice);
- for(int i = 0; i<(int)choice.size(); i++)
- {
- if(choice[i] == ' ')
- choice.erase(i, 1);
- }
- val = atoi(choice.c_str());
- if(selected[val-1] == 0)
- {
- money.push_back(val-1);
- selected[val-1] = 1;
- cout << "You choose box number " << val << " which contains " << boxes[val-1]<< ".\n\n";
- gCount++;
- total++;
- amount += boxes[val-1];
- }
- else
- {
- // ask over again
- }
- if( gCount == 3)
- {
- sixthRound = 0;
- cout << "\nSixth round is done.\n\nYou have opened a total of " << gCount << " boxes which helds a total amount of " << amount << ".\n";
- bankersOffer();
- // Wants the player to quit or continue?
- wantToDeal();
- }
- }
- // For later: give the player the oportunity to switch the remaining two boxes and open the one on the "table"
- }
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement