Simple problem of array

I can find records of account holders whom data are stored in a structure. I have used the array of structure data type. But when the record is not found in the array of structure data type, it should display the message "Record not Found" only once.

Below is my program and please correct it as per the requirement mentioned above.

#include<iostream.h>
#include<stdlib.h>

int main()
{
int choice,accNo,i,j=0,k=0,l=0,m=0,found;
char accName[20],accType[10];

struct Account
{
int acc_No;
char name[20];
char type[10];
int balance;
};

Account acc[3];
for(i=0;i<3;i++)
{
cout<<"Please enter the Account No.: ";
cin>>acc[i].acc_No;
cout<<"Please enter the Account Holder Name: ";
cin>>acc[i].name;
cout<<"Please enter the Account type: ";
cin>>acc[i].type;
cout<<"Please enter the Account Balance: ";
cin>>acc[i].balance;
cout<<endl<<endl;
}

do
{

cout<<"Enter 1 to search account information by Account number:"<<endl;
cout<<"Enter 2 to search account information by Account holder name:"<<endl;
cout<<"Enter 3 to search number of user having particular Account type:"<<endl;
cout<<"Enter 4 to search number of user having Account balance greater than 10,000:"<<endl;
cout<<"Enter 5 to quit from program:"<<endl;
cin>>choice;
cout<<endl<<endl;

if(choice==1)
{
cout<<"Please enter the Account No to find: ";
cin>>accNo;
for(j=0;j<3;j++)
{
if(acc[j].acc_No==accNo)
{
found=1;
cout<<endl;
cout<<"Account NO."<<acc[j].acc_No<<endl;
cout<<"Account Holder Name:"<<acc[j].name<<endl;
cout<<"Account Type:"<<acc[j].type<<endl;
cout<<"Balance:"<<acc[j].balance<<endl;
cout<<endl;
}
}



}

else if(choice==2)
{
cout<<"Please enter the Account Name to find: ";
cin>>accName;
for(k=0;k<3;k++)

if(strcmp(acc[k].name,accName)==0)
{
cout<<endl;
cout<<"Account No.: "<<acc[k].acc_No<<endl;
cout<<"Account Name: "<<acc[k].name<<endl;
cout<<"Account Type: "<<acc[k].type<<endl;
cout<<"Account Balance: "<<acc[k].balance<<endl;
cout<<endl;
}
else cout<<"Information is not Available: "<<endl;

}
else if(choice==3)
{
cout<<"Please enter the Account Type to find: ";
cin>>accType;
for(l=0;l<3;l++)

if(strcmp(acc[l].type,accType)==0)
{
cout<<endl;
cout<<"Account No.: "<<acc[l].acc_No<<endl;
cout<<"Account Name: "<<acc[l].name<<endl;
cout<<"Account Type: "<<acc[l].type<<endl;
cout<<"Account Balance: "<<acc[l].balance<<endl;
cout<<endl;
}

else
cout<<"Information is not Available: "<<endl;
}
else if(choice==4)
{
for(m=0;m<3;m++)

if(acc[m].balance>10000)
{
cout<<endl;
cout<<"Account No.:"<<acc[m].acc_No<<endl;
cout<<"Account Name: "<<acc[m].name<<endl;
cout<<"Account Type: "<<acc[m].type<<endl;
cout<<"Account Balance: "<<acc[m].balance<<endl;
cout<<endl;
}
else cout<<"No user has balance greater than 10,000 "<<endl;
}


}
while(choice!=5);
system("PAUSE");
return 0;
}





















































































Topic archived. No new replies allowed.