(a) To read a country's name and display capital and per-ca pita income.
(b) To read name of tha capital city and displays country's namr and displays country's name and per capital income.
Display an error message in case of an incorrect input.
#include <iostream.h>
#include <conio.h>
struct country
{
char nm[30];
char capital[30];
float income;
};
void main()
{
country c[50];
for( int i=0; i<50 ; i++)
{
cout << "\n Country's name : ";
cin.getline(c[i].nm, 30);
cout << "\n Country's capital :";
cin.getline(c[i].capital,30);
cout << "\n Per capita income :";
cin >> c[i].income;
}
clrscr();
cout << "\n\n Sl No. \t Country \t Capital \t Per-Ca pita-Income \n :";
for( int i=0; i < 50 ; i++)
{
cout << i+1 << "\t" << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ;
}
cout << "\n *************************************************** \n ";
char ch = 'y';
char cap[30];
int flag = 0;
while(ch == 'y' || ch == 'Y')
{
cout << "\n Enter Capital name : ";
cin.getline(cap, 30);
for(int k =0; k <50 ; k++)
{
flag = 0;
if( strcmp( c[i].capital , cap ) == 0)
{
cout << c[i].nm << "\t" << c[i].capital << "\t" << c[i].income << "\n" ;
flag = 1;
}
if(flag == 0)
cout << " Match not found !! ";
cout<< "Do you want to continue ?(y/n)";
cin >> ch;
}
}
}
No comments:
Post a Comment