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
|
// 7 Days Coin Toss.cpp : main project file.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdlib.h>
#include <cmath>
#include <string>
using namespace std;
// Used to generate the random number for coin toss
int coinToss()
{
int randomNumber;
randomNumber = rand() % 2;
return randomNumber;
}
int Battles()
{
string Guess;
cout << "Now, General McClellan\nDo you Predict the Coin will land on Heads (H) or Tails (T)?" << endl;
cout << "Enter an H or a T." << endl;
cin >> Guess;
//While statement for input verification
while (Guess != "H" && Guess != "h" && Guess != "T" && Guess != "t")
{
cout << "You have picked an invalid option, please Choose only an 'H' or a 'T',\nwithout the single quotes.\n" << endl;
cin >> Guess;
}
//If statement for echo of player choice
if (Guess == "H" || Guess == "h")
{
cout << "You chose Heads." << endl;
return 1;
}
// echo of player choice
if (Guess == "T" || Guess == "t")
{
cout << "You chose Tails." << endl;
return 0;
}
return -1;
}
int main()
{
// String values to Hold Player guess = Guess, and the coin flip = toss.
srand((time(0))); //used to seed random number.
string Guess;
string toss;
int Heads, Tails;
int randomNumber, coin;
string Battle_Names[9] = { "Oak Groove", "Mechanicsville", "Battle 3", "Battle 4", "Battle 5", "Battle 6", "Battle 7", "Battle 8", "Battle 9" };
// Score keep
int mcvictor = 0;
int aivictor = 0;
//Coin flip value
Heads = 1;
Tails = 0;
//Main Program
cout << "It is July 1st, 1862. The final day of the Battle of Seven Days." << endl;
cout << " You are general McClellan, in charge of the unionists, we will flip a coin to determine the victor of \n small territories in the battle." << endl;
for (int x = 0; x < 3; x++) // Loop only first 3
{
cout << endl << "Battle " << x + 1 << " - " << Battle_Names[x] << "." << endl; // Prints battle # and battle name
randomNumber = coinToss();
coin = Battles();
if (randomNumber == 1)
toss = "Heads";
else
toss = "Tails"; // Give value to "tails"
cout << toss << " was flipped." << endl;
if (randomNumber == coin)
{
mcvictor++;
}
else
{
aivictor++;
}
//Output user and AI score.
cout << "The score is: \n McClellan : " << mcvictor << endl;
cout << " Lee : " << aivictor << endl;
}
return 0;
}
|