oid function "expected initializer before void"

I am getting this error "expected initializer before void" Please help!!!

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  #include <iostream>
using namespace std;

struct Person
{
    char name[50];
    int age;
    float salary;
};

void displayData(Person);   // Function declaration

int main()
{
    Person p;
    Person p1;

    cout << "Enter Full name: ";
    cin.get(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;
    displayData(p);

cout << "Enter Full name: ";
    cin.get(p1.name, 50);
    cout << "Enter age: ";
    cin >> p1.age;
    cout << "Enter salary: ";
    cin >> p1.salary;
    // Function call with structure variable as an argument
    displayData(p1);

    return 0;
}


void displayData(Person p)
void displayData(Person p1)
{
    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;

 


    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p1.name << endl;
    cout <<"Age: " << p1.age << endl;
    cout << "Salary: " << p1.salary;
}

So, I think that the function displayData should just have the option to print one time the name the age and the salary, and what will determinate witch person will you display (p or p1) you decide when you call the function. Like that:

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
43
44
45
46
47
48
49

 #include <iostream>
using namespace std;

struct Person
{
    char name[50];
    int age;
    float salary;
};

void displayData(Person p);   // Function declaration

int main()
{
    Person p;
    Person p1;

    cout << "Enter Full name: ";
    cin.getline(p.name, 50);
    cout << "Enter age: ";
    cin >> p.age;
    cout << "Enter salary: ";
    cin >> p.salary;
    displayData(p);

cout << "Enter Full name: ";
    cin.ignore();
    cin.getline(p1.name, 50);
    cout << "Enter age: ";
    cin >> p1.age;
    cout << "Enter salary: ";
    cin >> p1.salary;
    // Function call with structure variable as an argument
    displayData(p1);

    return 0;
}


void displayData(Person p)
{
    cout << "\nDisplaying Information." << endl;
    cout << "Name: " << p.name << endl;
    cout <<"Age: " << p.age << endl;
    cout << "Salary: " << p.salary;
    cout<<endl;
}
 


and I inputed the cin.ignore() too.
Line 39 you don't need two function definitions, so take that one out. In the function definition for displayData(Person p1) you can delete the part with p.name, p.age and p.salary. Function definitions only need to be defined once.
Topic archived. No new replies allowed.