/*
Odds or Evens
Nicholas Howes
Additional Features:
1. If the user fails to follow instructions, the computer will rig the game to punish them
*/
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
//Is the player odd or even
char playerSide;
//determines whether the computer should cheat
bool computerCheat = false;
//should the game keep going
bool gameOver = false;
//What round is it?
int roundNum = 1;
int playerScore, compScore;
//The mechanics of the game
void round ()
{
int playerNum;
int compNum;
int sum;
cout << endl << "Round " << roundNum << endl << "Please enter a number between 1 and 5:";
cin >> playerNum;
if (playerNum <= 0 || playerNum >= 6)
{
playerNum = rand()%5 + 1;
cout << "You have entered an invalid number. For this round, I'm going to assign you " << playerNum << ". \nIn the future, please choose either 1, 2, 3, 4, or 5. \n";
computerCheat = true;
}
if (computerCheat)
{
if (playerSide == 'o'&& playerNum%2) //player is odd and has entered an odd number
{
compNum = 3;
}
else if (playerSide == 'o') //player is odd and has entered an even number
{
compNum = 2;
}
else if (playerNum%2) // player is even and has entered and odd number
{
compNum = 4;
}
else //player is even and has entered an even number
{
compNum = 5;
}
}
else
{
compNum = rand()%5 + 1;
cout << "My number is " << compNum << endl;
}
sum = playerNum + compNum;
if (sum%2)
{
cout << "The sum is " << sum << ", which is odd. ";
if(playerSide == 'o')
{
cout << "You win this round.";
++playerScore;
}
else
{
cout << "I win this round.";
++compScore;
}
}
else
{
cout << "The sum is " << sum << ", which is even. ";
if(playerSide == 'e')
{
cout << "You win this round.";
++playerScore;
}
else
{
cout << "I win this round.";
++compScore;
}
}
cout << endl;
++roundNum;
}
int main ()
{
//Initializes random number generator
srand((unsigned)time(0));
cout << "Welcome to Odd or Even" << endl << "Would you like to be (O)dd or (E)ven? :";
cin >> playerSide;
if (playerSide == 'O' || playerSide =='o')
{
playerSide = 'o';
cout << "You have chosen Odd. \n";
}
else if (playerSide == 'E' || playerSide == 'e')
{
playerSide = 'e';
cout << "You have chosen Even. \n";
}
else
{
cout << "You have entered an invalid option. For this game, I'm going to assign you Odd.\n In the future, please choose either O or E. \n";
playerSide = 'o';
computerCheat = true;
}
while (gameOver == false)
{
if (playerScore > 1)
{
cout << "\nCongratulations, you win!\n";
gameOver = true;
}
else if (compScore > 1)
{
cout << "\nI win! Better luck next time\n";
gameOver = true;
}
else
{
round ();
}
}
system("PAUSE");
}