Feb 6, 2016 at 3:45am UTC
I am having trouble getting my program to get my program to display the data for the players that scored below average. It displays it really quick and then the console closes and I can't get it to stay displayed and not close.
#include <iostream>
#include <string>
using namespace std;
void inputData ();
void displayPlayerData ();
void calculateAverageScore ();
void displayBelowAverage ();
const int ARRAY_SIZE = 100;
string m_playerNames[ARRAY_SIZE];
string m_playerScores[ARRAY_SIZE];
int m_currentPlayer = 0;
int m_totalScore = 0;
int m_totalPlayers = 0;
double m_averageScore = 0;
int main()
{
inputData();
displayPlayerData();
calculateAverageScore();
displayBelowAverage();
return 0;
}
void inputData()
{
m_currentPlayer = 0;
while (m_currentPlayer < ARRAY_SIZE)
{
cout << "Enter Player Name (Q to quit)" << endl;
cin >> m_playerNames[m_currentPlayer];
if ((m_playerNames[m_currentPlayer] == "Q") || (m_playerNames[m_currentPlayer] == "q"))
{
break;
}
cout << "Enter Player Score" << endl;
cin >> m_playerScores[m_currentPlayer];
m_currentPlayer++;
}
m_totalPlayers = m_currentPlayer;
}
void displayPlayerData()
{
m_currentPlayer = 0;
cout << endl << "Players Summary:" << endl;
while (m_currentPlayer < m_totalPlayers)
{
cout << m_playerNames[m_currentPlayer] << ": " << m_playerScores[m_currentPlayer] << endl;
m_currentPlayer++;
}
}
void calculateAverageScore()
{
m_currentPlayer = 0;
m_totalScore = 0;
while (m_currentPlayer < m_totalPlayers)
{
m_totalScore += atoi(m_playerScores[m_currentPlayer].c_str());
m_currentPlayer++;
}
m_averageScore = m_totalScore / m_totalPlayers;
cout << endl << "Average score is " << m_averageScore << endl;
}
void displayBelowAverage()
{
m_currentPlayer = 0;
cout << endl << "Players not reaching average:" << endl;
while (m_currentPlayer <= m_totalPlayers)
{
if (atof(m_playerScores[m_currentPlayer].c_str()) < m_averageScore)
{
cout << m_playerNames[m_currentPlayer] << ": " << m_playerScores[m_currentPlayer] << endl;
}
m_currentPlayer++;
}
}