Saturday, March 5, 2011

a structure program about country names and findin the country name and then displaying all the other details.


#include<iostream.h>
#include<conio.h>
#include<string.h>
struct list
{char country[20];
 char capital[10];
 float pc;
 };

void readarray(list c[],int n)
{cout<<"\nenter country name capital and percapita income";
 for(int i=0;i<n;i++)

 cin>>c[i].country>>c[i].capital>>c[i].pc;

}

void searchcountry(list c[],int n)
{char cou[20];
 cout<<"\nenter the country to be searched";
 cin>>cou;
 for(int i=0;i<n;i++)
 {if(strcmp(c[i].country,cou)==0)
   cout<<"\t"<<c[i].capital<<"\t"<<c[i].pc; }}
void main()
{
clrscr();
list c[10];
int n;
cout<<"\nenter the no:";
cin>>n;
readarray(c,n);
searchcountry(c,n);
getch();
}

No comments:

Post a Comment