structures

hello, i m a newbie and i coded a structure as followes..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<string>
using namespace std;

#define n_employee 5

struct database {
 char name[30];
 short age;
 int salary;
} employee[n_employee];

void printdb (database);


int main() {

 int n;

  for (n=0;n<n_employee;n++) {
  cout<<"name: "<<endl;
  cin.getline(employee[n].name,30);
  cout<<endl;
  cout<<"age: "<<endl;
  cin>>employee[n].age;
  cout<<endl;
  cout<<"salary: "<<endl;
  cin>>employee[n].salary;
  cout<<endl;
  }
 for (n=0;n<n_employee;n++) {
  printdb(employee[n]);
  }
 return 0;
}

void printdb(database employee)
{
 cout<<employee.name<<"\t";
 cout<<employee.age<<"\t";
 cout<<employee.salary<<endl;
} 


the problem is for the first case (employee[0]) i am asked for name input.But after this (employee[1],employee[2]) i am not asked for name input but jumps to input for age and salary...please help

regards
When I changed your 'char name[30];' (8 line) to 'string name' and 'cin.getline(employee[n].name,30);' (22) to cin >> name;

then this code worked for me.

So I think the problem is that you mix the 'getline' and cin.
well i m sorry...ur mentioned way was working a bit faulty.. after ur code is inserted and executed i got::error undefined symbol 'name'.

when i refined wat u gave me
(cin>>name to cin>>employee[n].name)

its working fine..
thanks for giving assistance.

regards
Last edited on
You are right.
thaks screw :-)
Topic archived. No new replies allowed.