Program to enter the names of states and capital and display them properly. Also enter the name of state to print its Capital...

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<string.h>

void main()
{
char state[5][20], capital[5][20], srch[20];
int i,j, flag=0, p;
clrscr();
cout<<"Enter the Names of States & their  capitals:\n\n";

for(i=0;i<5;i++)
{
cout<<"Enter Name of State : ";
cin.getline(state[i],20);
cout<<"Enter State Capital : ";
cin.getline(capital[i],20);
cout<<endl;
}
clrscr();
cout.setf(ios::left);
cout<<setw(20)<<"State Name"<<setw(20)<<"Capital"<<endl;
cout<<setw(20)<<"----------"<<setw(20)<<"-------"<<endl;
for(i=0;i<5;i++)
{
cout<<setw(20)<<state[i]<<setw(20)<<capital[i]<<endl;
}

cout<<"\n\nEnter any state to get its capital name: ";
cin.getline(srch,20);

for(i=0;i<5;i++)
{
if(strcmpi(srch,state[i])==0)
 {
flag++;
p=i;
 }
}
if(flag==0)
cout<<"\nThe "<<srch<<" state is not in the list...\n";
else
{
cout<<"The capital of "<<srch<<" state is "<<capital[p]<<endl;
}
getch();
}

/*
::Output::

State Name          Capital
----------          -------
Punjab              Chandigarh
Haryana             Chandigarh
Uttar Pradesh       Lucknow
Bihar               Patna
West Bengal         Kolkatta


Enter any state to get its capital name: Bihar
The capital of Bihar state is Patna

*/



No comments

Post your comments

Powered by Blogger.