hw8_main.cpp
/*
Programmer: Jennifer Leopold
Date: October 31, 2016
File: hw8.cpp
Purpose: Program that generates answers for candidates
during a debate.
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()
{
char question[MAX_QUESTION_LENGTH];
int questionLength;
int candidateNum;
char answer[ANSWER_LENGTH];
int score[NUM_CANDIDATES] = {0}; // all entries init to 0
// Seed the random number generator
srand(time(NULL));
cout << "*** Welcome to the 2016 Presidential Debate ***\n";
// Ask NUM_QUESTIONS many questions, alternating between
// the candidates
for (int questionNum = 0; questionNum < NUM_QUESTIONS;
questionNum++)
{
candidateNum = questionNum % NUM_CANDIDATES;
cout << "\nEnter a question for candidate #"
<< (candidateNum + 1) << ": ";
cin.getline(question, MAX_QUESTION_LENGTH);
// Generate an answer for this candidate
constructAnswer(answer, candidateNum);
cout << answer << endl;
// Calculate the score for this question and this
// candidate's answer, adding to the candidate's
// total score
questionLength = strlen(question);
if (questionLength == 0)
questionLength = 1;
score[candidateNum] += scoreAnswer(answer)/questionLength;
}
// Output the candidates' scores and the debate winner
outputResults(score);
return 0;
}