Can someone tell me why i get the error code "ISO C++ forbids comparison between pointer and integer" for lines 135 and 149

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

//Structure used to store the name, number of the players, and the number of points of each player
struct Players 
{
    string name; //Name of the player
    int numPlayer; //Number of the Player
    int numPoints; //Point's scored by Player


};


const int MAXPLAYERS =12;

typedef struct  Players Roster[12];
int total;
int maxgoals = 0; 


void Greeting ();
void TotalPoints (Roster &Players);
void HighestScore (Roster &Players);
void DisplayAll (Roster &Players);



int main () 
{
    Roster SoccerPlayers;

    Greeting();
    for (int index=0; index< 12; index++) 
    {


        cout << "Enter Player's Name: ";
        getline(cin, SoccerPlayers[index].name);
        ;

        do
        {
            cout << "Enter Player's Uniform Number: ";
            cin >> (SoccerPlayers[index].numPlayer);

            if (SoccerPlayers[index].numPlayer<=0)
                cout << "Zero or negative number not allowed, Try Again" << endl;
        }while (SoccerPlayers[index].numPlayer<=0);

        do
        {
            cout << "Enter Player's Points: ";
            (cin >> SoccerPlayers[index].numPoints).get();

            if (SoccerPlayers[index].numPoints<=0)
                cout << "Zero or negative number not allowed, Try Again" << endl;
        }while (SoccerPlayers[index].numPoints<=0);

        cout << endl;
    }


    DisplayAll(SoccerPlayers);
    TotalPoints(SoccerPlayers);
    HighestScore(SoccerPlayers);







    return 0;

        }

void Greeting ()
{
    cout << "___________________________________________________" << endl;
    cout << "Welcome to the Soccer Team Data Analyzer" << endl;
    cout << "You will now be asked to enter the name" << endl;
    cout << "uniform number, and points earned for each player." << endl;
    cout << "___________________________________________________" << endl;

}




void DisplayAll (Roster &SoccerPlayers)
{
    cout << "Players Score Summary" << endl << endl;
    cout << "__________________________________________" <<endl;
    cout << "Name               Number            Score" << endl;
    cout << "__________________________________________" << endl;
    for (int index=0; index< MAXPLAYERS; index++)
    {
    cout << setw(20) <<left << SoccerPlayers[index].name;
    cout << setw(15) <<left << SoccerPlayers[index].numPlayer;
    cout << SoccerPlayers[index].numPoints << endl;
    }



}



void TotalPoints (Roster &SoccerPlayers)
{
    int TotalScore = 0;
    for (int index = 0; index < 2; index++)
    {

        TotalScore += (SoccerPlayers[index].numPoints);


    }
    cout << "The total score is: " << TotalScore << endl;
}



void HighestScore (Roster &SoccerPlayers) 
{
    int firstPlaceIndex;
    int secondPlaceIndex; 

    int max = SoccerPlayers[0].numPoints; // Set  the higest to the first persons score

    // Loop that runs through and each player and compares one player in the array w/ the one next to them
    for( int i = 0; index < 12; i++)
    {
        // If soceryPlayer's score at index i is greater than 
        if(SoccerPlayers[i].numPoints > max)
        {
            firstPlaceIndex = i;

        }
        cout << "The first place person: " << SoccerPlayers[i].name;
    }



    // Loop that runs through and each player and compares one player in the array w/ the one next to them
    for( int i = 0; index < 12; i++)
    {
    // If soceryPlayer's score at index i is greater than AND DOES NOT EQUAL FIRST PLACE INDEX
    // This way the highest score (1st Place is ignored and it stores the next highest score, which is the second one
    if(SoccerPlayers[i].numPoints > max && i != firstPlaceIndex)
    {
    secondPlaceIndex = i;
    }
        cout << "The second place person was: " << SoccerPlayers[i].name;
    }


}

Can someone tell me why i get the error code "ISO C++ forbids comparison between pointer and integer" for lines 135 and 149

135 is for( int i = 0; index < 12; i++)
149 is for( int i = 0; index < 12; i++)

You need to make sure the line numbers match so we can look at the correct code.

Whaterver is on line 135 and 149, you are comparing an integer with a pointer, just as the message says. Did you forget to dereference the pointer?

I don't see where you are declaring / defining the variable 'index', which is used as the terminator for the two loops on the lines in question. My guess is that it is defined elsewhere (in some header or other) as a pointer...

Hmmn... I am not sure. Is this a user defined class? If so ... I dont think you can use < or > without overloading it to take your object and compare it to an integer. Do you have more to the code than what you posted?

This article has been dead for over six months. Start a new discussion instead.