samedi 24 novembre 2018

Issue with creating an array of objects in a personal project c++

The purpose of this (obviously incomplete) project is just some practice with objects in my free time. I have run into the following error when testing the project and I am not sure exactly what the issue could be.

"expected unqualified-id before ‘[’ token Competitor[] listOfCompetitors = new Competitor[10];"

Any help is much appreciated.

main.cpp

#include <iostream>
#include <string>
#include competitor.cpp;


using namespace std;
int scoringMethod;
int numberOfCompetitors;

int main(int argc, char** argv){
cout<<"How would tou like to score the competition? (please enter an interger)"<<endl;
cout<< "1. Closest Total Points"<<endl<<"2. Closest Total Points Without Going Over" <<endl<<"3. Closest to team1 Score"<<endl<< "4. Closest to Opponent Score"<<endl<<endl;
cin>>scoringMethod;
cout<<endl<<"How many competitors do you have?"<<endl;
cin>>numberOfCompetitors;
Competitor[] listOfCompetitors = new Competitor[10];
string tempName;
int tempScore1, tempScore2;
for (int i = 0; i<numberOfCompetitors;i++){

    cout<<"Name of competitor number "<< i<<"?"<<endl;
    cin>>tempName;
    cout<<tempName<<"'s prediction for team1's score?"<<endl;
    cin>>tempScore1;
    cout<<tempName<<"'s prediction for the score of team1's opponent?"<<endl;
    cin>>tempScore2;

    listOfCompetitors[i] = new Competitor(tempName,tempScore1,tempScore2);
}    
cout <<endl<<"The program has reached the end successfully" << endl;
}

competitor.cpp

#include <iostream>
#include <string>

using namespace std;

class Competitor{
private:
string Name;
int team1Score;
int opponentScore;

public:
Competitor(){
    Name = "invalid";
    team1Score = opponentScore = 0;
}
Competitor(string nameIn, int inteam1Score, int inOpponentScore){
    Name=nameIn;
    team1Score=inteam1Score;
    opponentScore=inOpponentScore;
}
void printData(){
    cout<<this->Name<<"'s guess:"<<endl<<"team1: "<<bamaScore<< "     Opponent: "<<opponentScore<<endl;
}
};

Aucun commentaire:

Enregistrer un commentaire