#include #include using namespace std; /* InitBingoCard(): Fill the bingo array with 20 randomly selected values. The function should ensure that each value can only appear in the array once. DisplayBingo(): Display the bingo array to the user. If a given array location has not yet been correctly guessed, it will be displayed as an asterisk. Correctly guessed values are displayed to the user at all times. UserGuess(): Asks the user to enter a value between 1 and 50. If the user is entering a number already previously used, you should instruct the user to select a different number. CheckBingo(): This function is passed the user's guess as well as the bingo array and determines if the guessed value is in the array. If it is, the function returns a 1, otherwise it returns a 0. DisplayStats(): This function will display to the user the number of guess attempts, the number which were successful and the number which were unsuccessful. */ ////////////////// ///DisplayStats/// ////////////////// void DisplayStats(double found, int gn) { double rate = 0; //stats cout << "STATS:" << endl; cout << "------------" << endl; cout << found << " successful guesses" << endl; cout << (gn - found) << " unsuccessful guesses" << endl; if ((gn - found) == 0) rate = 100; else rate = (double)((found / gn) * 100); cout << rate << "% success rate" << endl; //pause system("pause"); } ////////////////// ///DisplayBingo/// ////////////////// int displaybingo(int *bingo, int *display) { //clearsceen system("cls"); int x = 0; for (x=0; x < 10; x++) //1-10 if (display[x] == 1) if (bingo[x] < 10) cout << " 0" << bingo[x] << " "; else cout << " " << bingo[x] << " "; else cout << " ** "; cout << endl; for (x=10; x < 20; x++) //11-20 if (display[x] == 1) cout << " " << bingo[x] << " "; else cout << " ** "; cout << endl; return 0; } //////////////// ///CheckBingo/// //////////////// int checkbingo(int *guess, int *display, int *bingo, int& gn, double& found) { int x = 0; int i = 0; for (i=0; i < gn; i++) // dupe check if (guess[gn] == guess[i]) { cout << "number already entered." << endl; gn = gn - 1; i = 50; system("pause"); return 0; } for (x=0; x < 20; x++) // bingo check if (guess[gn] == bingo[x]) { cout << "you found a number!" << endl; display[x] = 1; found = found + 1; system("pause"); } return 0; } /////////////// ///UserGuess/// /////////////// int userguess(int *guess, int& gn) { int i = 0; do { cout << "GN " << gn << endl; cout << "enter number you wish to guess" << endl; cin >> guess[gn]; if (guess[gn] > 50 || guess[gn] < 1)//error check { cout << "number must be within 1 - 50 range" << endl; guess[gn] = 0; // gn = gn - 1; system("pause"); system("cls"); } }while(guess[gn] > 50 || guess[gn] < 1); return 0; } /////////////////// ///InitBingoCard/// /////////////////// int initbingocard(int *bingo) { int x = 0; int i = 0; int j = 0; int temp = 0; for (x=0; x != 20; x++) { bingo[x]=rand()%50+1; //generates number between 1 - 50 for (i=0; i < x; i++) //dupecheck if (bingo[x] == bingo[i])//if duplicate is found, current number is regenerated { x = x - 1; i = x; } } //bubble sort for (i=0; i<20; i++) for (j=i+1; j<20; j++) if (bingo[i] > bingo[j]) { temp = bingo[i]; bingo[i] = bingo[j]; bingo[j] = temp; } return 0; } ////////// ///Main/// ////////// int main() { srand(time(0));//random seed generator int bingo[20]; int guess[50]; int display[20]; int gn = 0; double found = 0; int temp = 0; //number generation + sorting initbingocard(bingo); do { //displays correct guesses displaybingo(bingo, display); //user guess input + dupe checking userguess(guess, gn); //checks if guess is in bingo array checkbingo(guess, display, bingo, gn, found); gn = gn + 1; //guess counter //display DisplayStats(found, gn); }while(found!=20); cout << " YOU've WON THE GAME!" << endl; return 0; }