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
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Function prototypes declared before main function
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef);
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers);
double CalculateAverageScore(const int scoreAr[], int numPlayers);
void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore);
// declaring variables
string playerNameAr[100];
double scoreAr[100];
int numPlayers = 0;
double averageScore;
const int arraySize = 100;
void main()
{
const string playerNameAr[100];
const double scoreAr[100];
int numPlayers = 0;
double averageScore;
InputData(playerNameAr, scoreAr, numPlayers);
DisplayPlayerData(playerNameAr, scoreAr, numPlayers);
averageScore = CalculateAverageScore(scoreAr, numPlayers);
DisplayBelowAverage(playerNameAr, scoreAr, numPlayers, averageScore);
}
// function definitions go here
// InputData Function
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef)
{
int numPlayers = 0;
const int arraySize = 100;
while (numPlayersRef < arraySize)
{
cout << "Enter Player Name (Q to quit): " << endl;
getline(cin, playerNameAr[numPlayersRef]);
if (playerNameAr[&numPlayerRef] == "Q")
break;
cout << "Enter score for " << playerNameAr[numPlayersRef] << ": ";
cin >> scoreAr[numPlayersRef];
numPlayersRef++;
}
}
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers)
{
int i = 0;
numPlayers = 0;
for(i < numPlayers)
{
cout << playerNameAr[i] << scoreAr[i] << endl;
i++;
}
}
double CalculateAverageScore(const int scoreAr[], int numPlayers)
{
int i;
double averageScore, totalScore;
for (i = 0, totalScore = 0; i < numPlayers; i++)
{
totalScore += scoreAr[i];
averageScore = totalScore / numPlayers;
cout << "Average Score: " << averageScore << endl << endl;
return averageScore;
}
void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore)
{
cout << "Players who scored below average ";
cout << setw(10) << left << " Name" << setw(5) << right << "Score" << endl;
for(int i = 0; i < numPlayers; i++)
if(scoreAr[i] < averageScore)
cout << setw(10) << left << playerNameAr[i] << setw(5) << right << scoreAr[i] << endl;
}
}
|
This is the errors that the compiler spits out.
1>------ Build started: Project: CIS170C_ilab5A, Configuration: Debug Win32 ------
1> playerprogram.cpp
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(19): error C2734: 'scoreAr' : const object must be initialized if not extern
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(22): error C2664: 'InputData' : cannot convert parameter 1 from 'const std::string [100]' to 'std::string []'
1> Conversion loses qualifiers
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(23): error C2664: 'DisplayPlayerData' : cannot convert parameter 2 from 'const double [100]' to 'const int []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(24): error C2664: 'CalculateAverageScore' : cannot convert parameter 1 from 'const double [100]' to 'const int []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(25): error C2664: 'DisplayBelowAverage' : cannot convert parameter 2 from 'const double [100]' to 'const int []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(37): error C2065: 'numPlayerRef' : undeclared identifier
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(48): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(48): error C2143: syntax error : missing ';' before ')'
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(48): error C2143: syntax error : missing ';' before ')'
1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(66): error C2601: 'DisplayBelowAverage' : local function definitions are illegal
1> c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(55): this line contains a '{' which has not yet been matched
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========