I am writing a program to record score of a cricket match. One array stores information of batting teams and the other array stores information of bowling team.
The program has to read the information of the teams and depending upon the user’s choice, it must displays either the batting team or the bowling team’s information.
My program does not display the information correctly.
What is the problem?
#include<iostream.h>
struct batting{
char name[20];
int score;
int out;
};
struct bowling{
char name[20];
int maiden;
int runs;
int wickets;
};
int main()
{
int i,j;
cout<<"How many number of batting&bowling team:";
cin>>i;
batting *bat=new batting[i];
batting *bat1;
bowling *bow=new bowling[i];
bowling *bow1;
for(j=0;j<i;j++)
{
bat1=&bat[j];
cout<<"\nEnter name:";
cin.getline((*bat1).name,20);
cin.ignore(1000,'\n');
//cin.ignore();
cout<<"\nEnter score:";
cin>>(*bat1).score;
cout<<"\nIndication out(out=1&in=0)";
cin>>(*bat).out;
}
for(j=0;j<i;j++)
{
bow1=&bow[j];
cout<<"\nEnter name:";
cin.getline((*bow1).name,20);
cin.ignore(1000,'\n');
cout<<"\nEnter maiden:";
cin>>(*bow1).maiden;
cout<<"\nEnter no: of runs";
cin>>(*bow1).runs;
cout<<"\nEnter wickets no:";
cin>>(*bow1).wickets;
}
int k=0;
cout<<"\n*******Which Information You would like to know?*******";
cout<<"\nEnter 1 for Batting team && 2 for bowling team";
cin>>j;
if(j==1)
for(k=0;k<i;k++)
{
bat1=&bat[k];
cout<<"\nName:"<<(*bat1).name;
cout<<"\nScore:"<<(*bat1).score;
cout<<"\nOut:"<<(*bat1).out;
}
return 0;
}