Hi im creating a linked list with these data types
etc
int account_number
char firstName[10]
char lastName[10]
float total_Balance

would anyone give a simple instruction to input/output these. i have tried everything but still doesnt work so far i have done this.

#include<iostream>
using namespace std;
struct account_query
{
int account_number;
char firstName[10];
char lastName[10];
float total_Balance;
};
struct link
{
account_query data;
link * next;
};

class Records
{
private:
link * first;
public:
Records( )
{ first = NULL; }
void write_rec( );
};
///////////////////////////////


  void Records::write_rec()
        {
          link *newlink;
          newlink=new link;
          cout<<"please enter account_number";
 cin>>newlink->link->data->account_query->account_number; //problem
          cout<<"please enter firstName";
 cin>>newlink->firstName;                                //problem
          cout<<"please enter lastName";
 cin>>newlink->lastName;                                //problem
          cout<<"please enter total_Balance";
  cin>>newlink->total_Balance;                          //problem
          newlink->next = first;
          first = newlink;
        }
/////////////////////////////////////////////////////////

void main()
{
Records s;
while(true)
{s.write_rec();}
system("pause");

}

Recommended Answers

All 2 Replies

line 13 should be cin>>newlink->link->data->account_number; Compare that with the other errors you posted and you will see what's wrong with them.

cin>>newlink->data->account_number;
cin>>newlink->data->firstName;
cin>>newlink->data->lastName;
cin>>newlink->data->total_Balance;

you created an object from link that named newlink.you dont use of struct type "link" in statements.the case of account_query is similar too.
instead you should use of objects name's.
link ---> newlink
account_query ---> data

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.