Getting errors when trying to complile this can anyone see what i may be doing wrong?

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 ==========
I Don't Mean To Be Mean,But Maybe You Could Shorten Your Code And Give Me The Line The Error Was In Please.Other Than That,I Would Be Happy To Help.And Also include THe State of the error.(Syntax,Building Error,ext) (: Good Luck On Your Code!!!
Last edited on
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

The following array of const elements shall be initialized.

1
2
    const string playerNameAr[100];
    const double scoreAr[100];


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


The first argument of the function call

InputData(playerNameAr, scoreAr, numPlayers);

is a const array while the first parameter of the function is declared without const quakifier

void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef);


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 []'


The second parameter of the function DisplayPlayerData is defined as
const int []

void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers);

while you are trying to pass as the second argument an array of type const double[]

DisplayPlayerData(playerNameAr, scoreAr, numPlayers);

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 []'


The same error as above.

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 []'


The same error as above.

1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(37): error C2065: 'numPlayerRef' : undeclared identifier


The third parameter of function InputData is named as numPlayersRef
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef)

However inside its body identificator numPlayerRef is used instead of numPlayersRef

if (playerNameAr[&numPlayerRef] == "Q")


Then some other synactical errors follow.

You must youself read error messages and update your code.
Its alright and yea sure so ill list each error separately with the type of error/syntax.


1
2
3
4
5
6
7
8
9
10
11
{
    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);
    }



For this line i am getting

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


Next error i am getting is for the following code:

1
2
 if (playerNameAr[&numPlayerRef] == "Q")


giving error

1>c:\users\devry university.jerwolfe-pc\documents\visual studio 2010\projects\cis170c_ilab5a\cis170c_ilab5a\playerprogram.cpp(37): error C2065: 'numPlayerRef' : undeclared identifier


Next error

1
2
  for(i < numPlayers)



and for this i am getting

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 ')'


And lastly

1
2
3
4
 }
    void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore)
    {


giving error

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


Sorry i am a beginner at C++ so i just would like someone to walk through with me to see what these errors mean and how to fix them. I learn better with having someone explain to me and show me then just reading from a text book. Thanks!
In line 20, i think you must initialize the constant immediately.

No 23 must be: InputData(playerNameAr[], scoreAr[], numPlayers);

In 24, the function proto says the 2nd parameter is a const int, but u passed a const double.-check line 25, 26 also

Check the spelling in line 38

In 49, write it like this:
1
2
3
4
for(;i < numPlayers;i++)
    {
    cout << playerNameAr[i] << scoreAr[i] << endl;
    }


Okay so for line 24 when you say i passed it as a const double and its supposed to be const int what do you mean by that? what are the difference between the two?
Okay so I've made some changes to my code and got rid off all of the existing errors, but now i have a problem... this win 32 concsole program is supposed to run and get and an out put similar to this.

Enter Player Name (Q to quit): Bob
Enter score for Bob: 3245
Enter Player Name (Q to quit): Sue
Enter score for Sue: 1098
Enter Player Name (Q to quit): Dave
Enter score for Dave: 8219
Enter Player Name (Q to quit): Pat
Enter score for Pat: 3217
Enter Player Name (Q to quit): Q

Name Score
Bob 3245
Sue 1098
Dave 8219
Pat 3217

Average Score: 3944.75

Players who scored below average
Name Score
Bob 3245
Sue 1098
Pat 3217
Press any key to continue . . .


But i can not get it to calculate the average score or list any of the names after you type Q, any advice?


here is my new code...

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

 #include <iostream>
#include <iomanip>
#include <string>
 
using namespace std;
 
const int ARRAY_SIZE = 100;
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);
 
void main()
{
    string playerNameAr[ARRAY_SIZE];
    int scoreAr[ARRAY_SIZE];
    int numPlayers = 0;
    int numPlayersRef = 0;
    double averageScore = 0;
 
    cout << fixed << showpoint << setprecision(2);
    InputData(playerNameAr, scoreAr, numPlayersRef);
    DisplayPlayerData(playerNameAr, scoreAr, numPlayers);
    CalculateAverageScore(scoreAr, numPlayers);
    DisplayBelowAverage(playerNameAr, scoreAr, numPlayers, averageScore);
    system("PAUSE");
}
void InputData(string playerNameAr[], int scoreAr[], int &numPlayersRef)
{
    while(numPlayersRef < ARRAY_SIZE)
    {
        cout << "Please enter player's name (press Q to quit):  ";
        getline(cin, playerNameAr[numPlayersRef], '\n');
        cout << endl;
        if ((playerNameAr[numPlayersRef] == "Q") || (playerNameAr[numPlayersRef] == "q"))
            break;
        cout << "Please enter " << playerNameAr[numPlayersRef] << "'s score:  ";
        cin >> scoreAr[numPlayersRef];
        cout << endl;
        cin.ignore();
        numPlayersRef++;
    }
}
 
void DisplayPlayerData(const string playerNameAr[], const int scoreAr[], int numPlayers)
{
    cout << setw(10) << left << "\n Name"
        << setw(5) << right << "Score" << endl;
    for (int i = 0; i < numPlayers; i++)
    {
        cout << setw(10) << left << playerNameAr[numPlayers]
        << setw(5) << right << scoreAr[numPlayers] << endl;
    }
}
 
double CalculateAverageScore(const int scoreAr[], int numPlayers)
{
    int i;
    double averageScore = 0, totalScore;
    for (i = 0, totalScore = 0; i < numPlayers; i++)
    {
        totalScore += scoreAr[i];
    }
    averageScore = totalScore/i;
    cout << fixed << showpoint << setprecision(2);
    cout << averageScore << endl << endl;
    return averageScore;
}
void DisplayBelowAverage(const string playerNameAr[], const int scoreAr[], int numPlayers, double averageScore)
{
    cout << "Players who scored below average\n";
    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;
}
Topic archived. No new replies allowed.