hw8.cpp

/*

Programmer: Jennifer Leopold

Date: March 23, 2018

File: hw8.cpp

Purpose: Program that randomly picks sayings from files in order

for two characters to have a telephone conversation.

Two other characters monitor the conversation for

certain words, competing in a "bingo" game.

To compile: g++ hw8.cpp hw8fncts.cpp -o hw8

To execute: ./hw8

*/

#include <iostream>

#include <cstdlib>

#include <ctime>

#include "hw8_functs.h"

using namespace std;

int main()

{

Player players[2];

char message[MAX_SENTENCE_SIZE];

int numExchanges = 0;

// Seed the random number generator

srand(time(NULL));

cout << "*** Welcome to Telephone Bingo ***\n\n";

// Get players' names and their Bingo cards

initializePlayers(players);

// Output each player's Bingo card

for (int i=0; i < 2; i++)

{

cout << "\nCard " << i+1 << ":\n";

outputBingoCard(players[i].bingoCard, cout, false);

}

// Exchange random utterances between Beatrice and BoJack,

// matching words that they say on the 2 Bingo cards.

// Telephone call ends when one contestant gets "Bingo"

// or there have been MAX_NUM_EXCHANGES of (pairs of)

// messages exchanged.

sayHello();

do

{

numExchanges++;

getRandomMessage(BEATRICE_FILE, message);

cout << BEATRICE << ": " << message << endl;

matchWordsOnBingoCard(players[0].bingoCard, message);

matchWordsOnBingoCard(players[1].bingoCard, message);

getRandomMessage(BOJACK_FILE, message);

cout << BOJACK << ": " << message << endl;

matchWordsOnBingoCard(players[0].bingoCard, message);

matchWordsOnBingoCard(players[1].bingoCard, message);

players[0].winner = checkForBingo(players[0].bingoCard);

players[1].winner = checkForBingo(players[1].bingoCard);

} while ((numExchanges <= MAX_NUM_EXCHANGES) &&

(!players[0].winner) && (!players[1].winner));

sayGoodbye();

// Announce Bingo game results and award prize(s)

outputResults(players);

return 0;

}