1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
//func prototyping
int beginGame(int playedBoard[]);
void displayBoard(int board[][3]);
void instructions();
bool testWinner(int ans, int boardNum, int ansBoard[]);
int main()
{
//Board "0" in c++
int board1[4][3] = { 38, 11, 83,
15, 6, 33,
10, 2, 20,
86, NULL, 95 };
int board2[4][3] = { 28, 10, 55,
89, 17, 98,
22, 4, 31,
69, NULL, 78 };
int board3[4][3] = { 90, 9, 45,
66, 12, 48,
34, 7, 70,
44, NULL, 26 };
int ansArray[3] = { 14,15,8 };
int usedBoards[3] = { NULL };
int userInput, NumberOfWins = 0, guesses = 0, boardNumber, ans, randomNum;
bool correct;
int main_board[4][3];
instructions(); //call upon instructions
beginGa me(usedBoards);
do
{
displayBoard(main_board);
cout << endl << "Enter your guess or zero to exit";
cin >> userInput;
if (userInput == 0) {
cout << endl << "Quitting";
return 0;
}
else {
while (userInput <0)
cin >> userInput;
}
} while
(testWinner(userInput, boardNumber, ansArray));
if (correct == true)
{
switch (boardNumber)
{
case 0:
NumberOfWins++;
usedBoards[0] = 1;
}
}
else if (correct == true && ((usedBoards[0] != NULL) || (usedBoards[1] != NULL) || (usedBoards[2] != NULL)))
{
cout << endl << "Do you want to play again or exit (0)";
cin >> userInput;
if (userInput == 0) {
cout << endl << "Quitting";
return 0;
}
else {
while (userInput < 0)
{
cout << endl << "Please enter a valid value";
cin >> userInput;
}
}
if (userInput != 0)
{
beginGame(usedBoards);
}
}
else
{
guesses++;
if (guesses > 3)
{
cout << endl << "Do you want to play again?. 1 to play again, 0 to exit";
cin >> userInput;
if (userInput == 0) {
cout << endl << "Quitting";
return 0;
}
else {
while (userInput < 0)
{
cout << endl << "Please enter a valid value";
cin >> userInput;
}
}
if (userInput != 0)
{
beginGame(usedBoards);
}
}
}
while (usedBoards[0] != NULL || usedBoards[1] != NULL || usedBoards[2] != NULL);
cout << endl << "You are the number guessing Champion";
return 0;
}
}
{
{
}
return 0;
}
int beginGame(int playedBoard[])
{
int randomNum;
int boardNum;
//Generate a random number between 1 and 3
//check to see if this board has not been played
//return random number
//else loop back around and generate new random number
{
int randomNum;
while (true) {
randomNum = rand() % 3;
if (playedBoards[randomNum] != 1)// if not already played
break;
}
return randomNum;
}
}
void displayBoard(int board[][3])
{
//remember to display ? look for NULL value, i.e if NULL
//Hint you will need two for loops
{
for (int x = 0; x < 4; x++)
{
for (int y = 0; y < 3; y++)
{
cout << setw(4) << board[x][y] << " ";
}
cout << endl;
}
}
}
void instructions()
{
cout << "**********************************" << endl;
cout << endl << "MISSING NUMBERS GAME" << endl;
cout << "A Fun Brain Game" << endl << endl << endl;
cout << "Please enter a whole number to guess the missing number...";
cout << endl << "Program Developed by: Austin Sisti" << endl;
cout << "**********************************" << endl;
}
bool testWinner(int ans, int boardNum, int ansBoard[])
{
//check to see if the ans <which is the answer that the user entered) is equal to
//the answer in the ansBoard.
//if answered correnctly output nice job... and return true
//else output incorrect... and return false
{
if (ans == ansBoard[boardNum])
{
cout << endl << "Nice Job!!";
return true;
}
else
{
cout << endl << "Sorry, that is incorrect";
return false;
}
}
}
|