Code check

Can someone advise where im going wrong with the below code??


#include<fstream.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<graphics.h>
int query=1;
class manutd
{
public:
char pname[50];
int goals,salary;
}player[17],rplayer[17],r2player[17];

class teams
{public:
char team_name[50];
int skill;
}team[19];

class trnsfr
{
public:
char tname[50];
int tsal;
}tplayer[15];

class general
{
public:
int week;
int mskill;
int tot_goals;
}ob,ob2;

void welcome_screen()
{
clrscr();
textcolor(RED);
gotoxy(10,10);
cout<<"**************** W E L C O M E *********************** ";
gotoxy(15,12);
cout<<"*** T O M A N C H E S T E R U N I T E D *** " ;
gotoxy(10,14);
textcolor(RED);
cout<<"******* C L U B M A N A G E M E N T ******* ";
gotoxy(28,16);
textcolor(RED);
gotoxy(10,20);
cout<<"";

textcolor(RED+BLINK);
gotoxy(20,30);
cout<<" *** PRESS ANY KEY TO CONTINUE***";
getch();
return;
}
void initiate()
{
//Player Names
strcpy(r2player[1].pname,"Edwin Van Der Sar");
strcpy(r2player[2].pname,"Patrice Evra");
strcpy(r2player[3].pname,"John O'Shea");
strcpy(r2player[4].pname,"Rio Ferdinand");
strcpy(r2player[5].pname,"Nemanja Vidic");
strcpy(r2player[6].pname,"Darren Fletcher");
strcpy(r2player[7].pname," Michael Carrick");
strcpy(r2player[8].pname," Cristiano Ronaldo");
strcpy(r2player[9].pname," Ryan Giggs");
strcpy(r2player[10].pname," Carlos Tevez");
strcpy(r2player[11].pname," Wayne Rooney");
strcpy(r2player[12].pname," Ben Foster");
strcpy(r2player[13].pname," Rafael De Silva");
strcpy(r2player[14].pname," Ji Sung Park");
strcpy(r2player[15].pname," Dimitar Berbatov");
strcpy(r2player[16].pname," Johny Evans");
strcpy(r2player[17].pname," Paul Scholes");
ob.week=0;
ob.tot_goals=0;
ob2.week=0;
ob2.tot_goals=0;
query++;
//initiations of goals from 0
for(int i=1;i<=17;i++)
{
r2player[i].goals=0;
}

//specify salary given to each player
r2player[1].salary=5000;
r2player[2].salary=3000;
r2player[3].salary=4000;
r2player[4].salary=5000;
r2player[5].salary=4500;
r2player[6].salary=3500;
r2player[7].salary=4000;
r2player[8].salary=7500;
r2player[9].salary=6000;
r2player[10].salary=5000;
r2player[11].salary=6500;
r2player[12].salary=2500;
r2player[13].salary=2500;
r2player[14].salary=3000;
r2player[15].salary=4000;
r2player[16].salary=3000;
r2player[17].salary=5000;
//ob.tot_sal=0;
//for(int j=1;j<=17;j++)
//{
//ob.tot_sal+=player[j].salary;
//}


//Tranfer Players
strcpy(tplayer[1].tname,"Roque Santa Cruz");
tplayer[1].tsal=3000;
strcpy(tplayer[2].tname,"Lionel Messi");
tplayer[2].tsal=6500;
strcpy(tplayer[3].tname,"Amir Zaki");
tplayer[3].tsal=3000;
strcpy(tplayer[4].tname,"Ricardo Kaka");
tplayer[4].tsal=5500;
strcpy(tplayer[5].tname,"Ibrahamovic");
tplayer[5].tsal=4500;
strcpy(tplayer[6].tname,"Luka Modric");
tplayer[6].tsal=4000;
strcpy(tplayer[7].tname,"Peter Crouch");
tplayer[7].tsal=3000;
strcpy(tplayer[8].tname,"Bastian Schweinsteiger");
tplayer[8].tsal=4000;
strcpy(tplayer[9].tname,"Deco");
tplayer[9].tsal=4500;
strcpy(tplayer[10].tname,"Franck Ribery");
tplayer[10].tsal=5000;
strcpy(tplayer[11].tname,"Karim Benzema");
tplayer[11].tsal=2500;
strcpy(tplayer[12].tname,"Mamadou Sakho");
tplayer[12].tsal=2000;
strcpy(tplayer[13].tname,"Wilson Palacios");
tplayer[13].tsal=2500;
strcpy(tplayer[14].tname,"Douglas Costa");
tplayer[14].tsal=2500;
strcpy(tplayer[15].tname,"Nicolas Bertolo");
tplayer[15].tsal=3000;

//EPL Teams:
strcpy(team[1].team_name,"Liverpool");
team[1].skill=18;
strcpy(team[2].team_name,"Chelsea");
team[2].skill=18;
strcpy(team[3].team_name,"Arsenal");
team[3].skill=17;
strcpy(team[4].team_name,"Aston Villa");
team[4].skill=15;
strcpy(team[5].team_name,"Everton");
team[5].skill=14;
strcpy(team[6].team_name,"Fulham");
team[6].skill=13;
strcpy(team[7].team_name,"Tottenham");
team[7].skill=15;
strcpy(team[8].team_name,"West Ham United");
team[8].skill=13;
strcpy(team[9].team_name,"Manchester City");
team[9].skill=15;
strcpy(team[10].team_name,"Wigan Athletic");
team[10].skill=13;
strcpy(team[11].team_name,"Stoke City");
team[11].skill=12;
strcpy(team[12].team_name,"Bolton Wanderers");
team[12].skill=12;
strcpy(team[13].team_name,"Blackburn Rovers");
team[13].skill=13;
strcpy(team[14].team_name,"Portsmouth");
team[14].skill=13;
strcpy(team[15].team_name,"Sunderland");
team[15].skill=12;
strcpy(team[16].team_name,"Newcastle United");
team[16].skill=11;
strcpy(team[17].team_name,"Hull City");
team[17].skill=10;
strcpy(team[18].team_name,"Middlesbrough");
team[18].skill=9;
strcpy(team[19].team_name,"West Bromwich Albion");
team[19].skill=7;

ob.mskill=19;
}

void view_team()
{
clrscr();
ifstream fin("manutd.txt",ios::in);
for(int i=1;i<=17;i++)
{
fin.read((char*)&rplayer[i],sizeof(rplayer[i]));
}
fin.close();

textcolor(RED);
cout<<"\n\tMANCHESTER UNITED";
for(int j=1;j<=17;j++)
{
cout<<"\nPlayer Name: ";
puts(rplayer[j].pname);
cout<<"\nGoals Scored: "<<rplayer[i].goals;
}
cout<<"\n\tTotal Goals scored: "<<ob2.tot_goals;
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}

void save()
{
clrscr();
ofstream fout("manutd.txt",ios::out|ios::app);
fout<<ob2.week;
for(int i=1;i<=17;i++)
{
fout.write((char *)&r2player[i],sizeof(r2player[i]));
}
fout.close();
cout<<" Data Saved!";
gotoxy(10,10);
textcolor(RED+BLINK);
cout<<"PRESS ANY KEY TO RETURN TO MENU";
getch();
}


void simulation()
{
clrscr();
int play[11];
ifstream weekin("manutd.txt",ios::in|ios::beg);
weekin>>ob2.week;
ob2.week++;
for(int i=1;i<=17;i++)
{
weekin.read((char*)&r2player[i],sizeof(r2player[i]));
}
weekin.close();
int n=ob2.week;
cout<<"Week Number: "<<ob2.week;
if(ob2.week>20)
{
n=ob2.week-20;
}
cout<<"\n\t Choose your team using the numbers given:";
for(int j=1;j<=17;j++)
{
cout<<"\n"<<j;
textcolor(RED);
puts(r2player[j].pname);
}
for(int h=1;h<=11;h++)
{
cin>>play[h];
if(play[h]>17 || play[h]<1)
{
cout<<"Wrong choice, Please re-enter";
cin>>play[h];
} }
clrscr();
cout<<"\n\t Your team:";
for(int g=1;g<=11;g++)
{
cout<<"\n";
puts(r2player[play[g]].pname);
cout<<"\n";
}

//scoring
int r=ob.mskill-team[n].skill;
int fg,ag;
srand(time(NULL));
if(r==1 || r==2)
{
fg=rand()%4;
ag=rand()%3;
}
else if(r==3 || r==4)
{
fg=rand()%5;
ag=rand()%3;
}
else if(r>=5 && r<=7)
{
fg=rand()%5+1;
ag=rand()%2;
}
else
{
fg=rand()%6+1;
ag=rand()%2;
}
ob2.tot_goals+=fg;
//player scores
int s[6];
for(int e=1;e<=fg;e++)
{
s[e]=rand()%11+1;
r2player[play[s[e]]].goals++;
}
cout<<"\n \t At full time, result: ";
cout<<"\n Manchester United "<<fg<<"-"<<ag<<" ";
puts(team[19].team_name);
cout<<"\n Scorer's for Manchester United=\n";
for(int y=1;y<=fg;y++)
{
cout<<"\n";
puts(r2player[play[s[y]]].pname);
}
getch();
return;
}

void transferweek()
{
clrscr();
char c;
int p,s,g;
cout<<"\tWeek 20";
cout<<"\nTRANSFER WEEK";
cout<<"Rules:\n";
cout<<"1)For buying a player, one player has to be sold";
cout<<"\n2)Value ofbought player has to be equal of less than\n sold player\n";
cout<<"\n Do you want to buy?(y/n)";
cin>>c;
switch(c)
{
case 'y':
case 'Y':
s=0;
break;
case 'n':
case 'N':
s=1;
break;
}
while(s=0)
{
cout<<"\nPress number next to desired player\nList of players:\n";
for(int i=1;i<=15;i++)
{
cout<<i;
puts(tplayer[i].tname);
cout<<"---"<<tplayer[i].tsal<<"\n";
}
cin>>p;
clrscr();
cout<<"\n Which player to sell?\n";
for(int q=1;q<=17;q++)
{
cout<<g;
puts(r2player[q].pname);
cout<<"---"<<r2player[q].salary<<"\n";
}
cin>>g;
if(r2player[g].salary>=tplayer[p].tsal)
{
strcpy(r2player[g].pname,tplayer[p].tname);
cout<<"\n \t Negotiations Accomplished. Congratulations!";
}
else
{}
cout<<"\n Another transfer? \n0.Yes 1.No\n";
cin>>s;
}}


void menu()
{
char ch;
clrscr();
//textbackground(WHITE);
textcolor(RED);
gotoxy(30,8);
cprintf(" N:NEXT WEEK ");
gotoxy(30,9);
cprintf(" V:VIEW TEAM INFORMATION \n \r ");
gotoxy(30,10);
cprintf(" S:SAVE DATA \n \r ");
gotoxy(30,11);
cprintf(" E:EXIT \n \r ");
ch=getch();

switch(ch)
{
case 'n':
case 'N':
if(ob2.week==19)
{
transferweek();
}
else{
simulation();}
break;
case 'v' :
case 'V' :
view_team();
break;
case 's':
case 'S':
save();
break;
case 'e':
case 'E':
system("cls");
exit(0);
}
}

void main()
{
clrscr();
welcome_screen();
initiate();
save();
menu();
getch();
}
What the problem? Hard to give a solution to an unknown problem. Btw please surround the posted code with [code]yourcode goes here ...[/code] for the future it makes it infinitely easier to read
I created this within Visual 2010 within the application win32 application Empty Project, then created .CPP file to the source folder then added the above code then tried to complie but got the below message, need to help to understand the issue's or advice if I should change parts of the code, re-structure etc?

Thanks in advance


1>c:\users\****\documents\visual studio 2010\projects\the real one\the real one\main.cpp(1): error C2146: syntax error : missing ';' before identifier 'Jul'
1>c:\users\****\documents\visual studio 2010\projects\the real one\the real one\main.cpp(1): error C2143: syntax error : missing ';' before 'constant'
1>c:\users\****\documents\visual studio 2010\projects\the real one\the real one\main.cpp(1): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\****\documents\visual studio 2010\projects\the real one\the real one\main.cpp(1): error C2059: syntax error : 'bad suffix on number'
1>c:\users\****\documents\visual studio 2010\projects\the real one\the real one\main.cpp(1): error C2059: syntax error : 'constant'
1>c:\users\***\documents\visual studio 2010\projects\the real one\the real one\main.cpp(5): fatal error C1083: Cannot open include file: 'fstream.h': No such file or directory
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.78
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0
Your biggest problem:

1
2
3
4
5
6
cout<<"**************** W E L C O M E *********************** ";
gotoxy(15,12);
cout<<"*** T O M A N C H E S T E R U N I T E D *** " ;
gotoxy(10,14);
textcolor(RED);
cout<<"******* C L U B M A N A G E M E N T ******* ";


SCUM!!

Are you creating a c++ program or c? Because most of your includes should be without the ".h" (for c++ that is):

1
2
3
4
5
6
7
#include<fstream>
#include<string>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<graphics.h> // not sure 


Have you changed the code since you're original post because the line numbers for the errors don't seem to match up with your code.
Last edited on
The original code was C, as I want to code this in C++ I will take out the ".h" out of the code

No Change to the code this could be down to the cut & Paste

Is there anything I need to change or take into consideration?
I don't think that MSVC has a graphics.h header. Also its conio.h isn't as functional as the old borland conio. And without these you cannot use functions like clrscr, gotoxy, textcolor etc.. Google win bgi to see what you can download and add to your project to fix this.
m4ster r0shi you will need to explain that in more detail?
What m4ster r0shi is saying is that you need to download the libraries which contain the definitions for these functions and link them to your project as they are not part of Visual 2010 by default. If you're not sure how to link with Visual studio just google it
I think there are better ways to get colors into your program...
But as far as that goes, it might actually be easier to turn it into a GUI program and put colors into that, then to try and get colors into a console program... And I personally think making a GUI in C++ is tedious at best. I use C# or something if I wanna make a GUI app, Though I hate the non-portability of .NET, but still easier anyway.

Anyways, I had to get rid of all the gotoxy's and color stuff to even get it to compile on g++. I also had to change a few things and, for my convenience, converted some of it to C++ (more so). And I added the correct headers.

Here is the code (it's too big for one post, lol): http://www.mediafire.com/?oim2rz2eydy
Last edited on
Hi RyanCaywood

Thanks, I will have a look at this
Topic archived. No new replies allowed.