ERROR IN THE CODE AND CORRECTIONS

can any one tell me the error in the code......and its soln.......


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct BATSMAN
{
char name[40];
int runs,overs_played;
char out;
char mode[20];
};

struct BATTING
{
BATSMAN batsman[11];
int tot_runs,tot_overs,extras;
};
struct BOWLING
{
char name[30];
int overs_bowled,runs_given;
int wickets_taken,maiden;
};

void main()
{
BATTING teamA;
BOWLING teamB[11];

cout<<"Enter the details of Batting team\n";
for(int i=0;i<11;i++)
{
cout<<"Enter the details of batsman "<<i+1<<":\n";
cout<<"Enter his name : ";
gets(teamA.batsman[i].name);
cout<<"Enter his runs : ";
cin>>teamA.batsman[i].runs;
cout<<"Enter the no. of overs played by him : ";
cin>>teamA.batsman[i].overs_played;
cout<<"Enter y if he is out else n : ";
cin>>teamA.batsman[i].out;
if(teamA.batsman[i].out=='y' || teamA.batsman[i].out=='Y')
{
cout<<"Enter the mode by which he is out : ";
gets(teamA.batsman[i].mode);
}
else
strcpy(teamA.batsman­­­[i].mode,"not out");
clrscr();

}
cout<<"Enter total runs of the team : ";
cin>>teamA.tot_runs;
cout<<"Enter total overs played by the team : ";
cin>>teamA.tot_overs;
cout<<"Enter extras gained by the team : ";
cin>>teamA.extras;
clrscr();
cout<<"Enter the details of bowling team:\n ";
cout<<"Enter the no of bowlers : ";
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter the details of bowler "<<i+1<<" :\n";
cout<<"Enter his name : ";
gets(teamB[i].name);
cout<<"Enter the overs bowled : ";
cin>>teamB[i].overs_bowled;
cout<<"Enter the no. of maiden overs : ";
cin>>teamB[i].maiden;
cout<<"Enter the no. of runs given : ";
cin>>teamB[i].runs_given;
cout<<"Enter the no. of wickets taken : ";
cin>>teamB[i].wickets_taken;
clrscr();
}
}
1
2
3
4
5
6
#include<iostream.h>//.h versions of headers are deprecated and should not been used in 21th century anymore
#include<iostream>
#include<conio.h>//You don't need this here
#include<stdio.h>//You don't use it anyway
#include<cstdio>//if you need it
#include<cstring>//But use strcpy, right? 


void int main()//Terrible error. Standard requires main() to return int. It isn't C
1
2
strcpy(teamA.batsman­­­[i].mode,"not out");
/*You might not see it but there is a bunch of symbols between batsman and [ i ]*/


And there is a bunch of C construct which mangles input stream and make your program to not work as it should.
Last edited on
Topic archived. No new replies allowed.