#include <iostream>
#include <iomanip>
#include <map>
#include <time.h>
#include <cstdlib>
using namespace std;
//displays the instruction of the game
void displayInst(){
for ( int b = 0; b < 28; b++ )
cout << "* ";
cout << "\n* Game Title: NUM-BERS *";
cout << "\n* *";
cout << "\n* Players : 2 *";
cout << "\n* *";
cout << "\n* How-to-play: The game is basically *";
cout << "\n* based on \"tic-tac-toe\" but with a *";
cout << "\n* twist. Instead of Using X's and O's *";
cout << "\n* the player is going to use numbers, *";
cout << "\n* ODD for PLAYER 1 and EVEN for PLAYER 2. *";
cout << "\n* The goal is to make a \"in a row\"; *";
cout << "\n* (diagonally, vertically,horizontally) *";
cout << "\n* but the catch is, the total of the row *";
cout << "\n* will be equal to the \"goal total\" *";
cout << "\n* generated by the program. *\n";
for ( int b = 0; b < 28; b++ )
cout << "* ";
}//end displayInst
int main(){
char choice;
do{
map<char,char> box;
box['a'] = 'a';
box['b'] = 'b';
box['c'] = 'c';
box['d'] = 'd';
box['e'] = 'e';
box['f'] = 'f';
box['g'] = 'g';
box['h'] = 'h';
box['i'] = 'i';
char letter,value;
int goalTotal;
//generates a random number for the total goal
srand( time(NULL) );
goalTotal = (5 + rand() % 15);
int a[8];
do{
displayInst();//displays the instructions
//display's the main board
cout << endl << endl << setw(6) << box['a']<<" | "<<box['b']<<" | "<<box['c'];
cout << "\n ---------\n";
cout << setw(6) << box['d'] << " | " << box['e'] << " | " << box['f'];
cout << "\n ---------\n";
cout << setw(6) << box['g'] << " | " << box['h'] << " | " << box['i'] << endl;
cout << setw(6) << "\nGoal Total to Win: " << goalTotal;//displays the total goal for the game
//lets the user input their move
cout << endl << setw(6) << "\nEnter a letter: ";
cin >> letter;
cout << endl << setw(6) << "Enter a value: ";
cin >> value;
box[letter] = value;
//check if player wins
a[0] = int(box['a'] - 48) + int(box['b'] - 48) + int(box['c'] - 48);
a[1] = int(box['d'] - 48) + int(box['e'] - 48) + int(box['f'] - 48);
a[2] = int(box['g'] - 48) + int(box['h'] - 48) + int(box['i'] - 48);
a[3] = int(box['a'] - 48) + int(box['d'] - 48) + int(box['g'] - 48);
a[4] = int(box['b'] - 48) + int(box['e'] - 48) + int(box['h'] - 48);
a[5] = int(box['c'] - 48) + int(box['f'] - 48) + int(box['i'] - 48);
a[6] = int(box['g'] - 48) + int(box['e'] - 48) + int(box['c'] - 48);
a[7] = int(box['a'] - 48) + int(box['e'] - 48) + int(box['i'] - 48);
if(a[0] == goalTotal) cout << "\nPlayer Wins\n";
if(a[1] == goalTotal) cout << "\nPlayer Wins\n";
if(a[2] == goalTotal) cout << "\nPlayer Wins\n";
if(a[3] == goalTotal) cout << "\nPlayer Wins\n";
if(a[4] == goalTotal) cout << "\nPlayer Wins\n";
if(a[5] == goalTotal) cout << "\nPlayer Wins\n";
if(a[6] == goalTotal) cout << "\nPlayer Wins\n";
if(a[7] == goalTotal) cout << "\nPlayer Wins\n";
}while(a[0] != goalTotal || a[1] == goalTotal || a[2] != goalTotal || a[3] != goalTotal || a[4] != goalTotal || a[5] != goalTotal || a[6] != goalTotal || a[7] != goalTotal);
cout << "Play again? (Y/N): ";
cin >> choice;
}while( toupper(choice) == 'Y');
return 0;
}
guys! can you please help on what do i have to do to end my program?
after the player wins it still continues to play the game..
i know its in the do-while.. but i'm confused on what to do.
but please can someone modify it?
thanks!