Code:code #include <iostream> #include <vector> #include <string> #include <ctime> #include <iomanip> #include <stdlib.h> using namespace std; string deal, choice, boxToKeep; const int n = 20; vector<int>sumTable; vector<double>boxes; vector<double>money; double values[n] = {1, 5, 10, 50, 100, 200, 500,1000, 2000, 5000, 10000, 20000,30000,50000,100000,120000,150000,200000,250000, 300000}; 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,}; 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 = 20; 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]]); } 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 <= 20) ) { 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 - 20 to open,beside that you have choose 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(); } } system("cls"); /code[/PHP]