I’m new to C++ and I am attempting to write a program that simulates a football game. I’m getting a compiler error that says the functions get_rank, get_player, and get_name are not declared in this scope. Any help is greatly appreciated!
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Player {
int playerNum;
string playerPos;
float playerRank;
public:
void set_values(int, string, float);
float get_rank(){ return playerRank; };
};
class Team {
Player team[];
string teamName;
public:
void set_values(Player[],string);
Player get_player(int a) { return team[a]; };
string get_name() { return teamName; };
};
void play(Team t1, Team t2){
float t1rank = 0.0;
float t2rank = 0.0;
for(int i=0; i<11; i++){
t1rank += get_rank(get_player(t1, i));
}
for(int j=0; j<11; j++){
t2rank += get_rank(get_player(t2, j));
}
if(t1rank>t2rank){
cout << get_name(t1) + " wins!";
}
else if(t2rank>t1rank){
cout << get_name(t2) + " wins!";
}
else{
cout << "It was a tie!";
}
}
It looks like you want to do something like:
In C++, method calls are of the form
object.method(args). In your case, you have two method calls, one whereobjectist1and the method isget_player, and the second where the object is the return value of the previous call, and the method isget_rank.