I've tried to write a program which shows the result of a soccer game, using a class Match
in C++.
Here is my code:
#include <iostream>
#include <conio.h>
using namespace std;
class Match {
private:
typedef struct team {
char name[50];
int goal ;
}echipa;
team e1;
team e2;
public:
void init_name(char team1_name[], char team2_name[]);
void init_goal(int g1, int g2);
void print();
};
void Match::init_name(char team1_name[], char team2_name[]) {
strncpy(e1.name, team1_name, sizeof(team1_name));
strncpy(e2.name, team2_name, sizeof(team2_name));
}
void Match::init_goal(int g1, int g2) {
e1.goal = g1;
e2.goal = g2;
}
void Match::print() {
cout << e1.name << " " << e1.goal<< " " << " - " << " " << e2.goal<< " " << e1.name << endl;
}
void main ()
{
Match x;
x.init_name("Team1", "Team2");
x.init_goal(5, 4);
x.print();
getch();
}
In console, instead of Team1 5 - 4 Team2
I have
Team╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠♣ 5 - 4 Team╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠♣
I have no idea why these characters ╠♣
appear everytime I run the code, any suggestion on how to fix this?