Check C Code

Started by
1 comment, last by Sneftel 13 years, 9 months ago
I have created this C code 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

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.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,sizeof(rplayer));
}
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.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,sizeof(r2player));
}
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,sizeof(r2player));
}
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.tname);
cout<<"---"<<tplayer.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

.tsal)
{
strcpy(r2player[g].pname,tplayer

.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();
}


This Is the Error that I get when I try to Build the Program:

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



Advertisement
Here's an explanation for the "fstream.h" error: fstream.h, I thought it was a standard header....

I couldn't find "Jul" in your code, but where ever that is, it's likely that whatever comes right before it is missing a semi-colon.

Also, on these forums please wrap large patches of code, with "source" tags. Check the faq for details.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:
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'

That sounds an awful lot like you somehow have a date (like "Jul 04") floating around in your code somewhere.

This topic is closed to new replies.

Advertisement