Hello
I have given a program in which i have to declare structure to store account ID, amount, user name and address. It inputs the number of account holders from the user and creat a dynamic array of structures to store the records of accounts. The program should declare two functions i.e. one for getting input from the user and other for showing records to the user.But my program is not fulfilling the requirements. It is not taking the inputs of name and address as it should. Got confused how to solve it.
#include<iostream.h>
#include<conio.h>
struct acc
{
int id;
double amount;
char name[50];
char add[150];
};
void input(acc *,int);
void output( acc *,int);
void main()
{
int n;
cout<<"Enter total number of accounts:";
cin>>n;
acc *ptr;
ptr=new acc[n];
input(ptr,n);
output(ptr,n);
delete []ptr;
getch();
}
void input(acc* x,int t)
{
int i;
for(i=0;i<t;i++)
{
cout<<"Enter customer id:";
cin>>x->id;
cout<<"Enter the name : ";
cin.get(x->name, 50);
cout<<"Enter amount:";
cin>>x->amount;
cout<<"Enter the address";
cin.get(x->add, 150);
x++;
}
}
void output(acc* y,int t)
{
for(int i=0;i<t;i++)
{
cout<<"Id :"<<y->id<<" name is : "<<y->name<<" amount: ";
cout<<y->amount<<" address is : "<<y->add<<endl;
y++;
}
}