Error: expected primary-expression before ‘)’ token

I'm getting this error when running this code

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;


struct staffTWB {
string staffName;
int staffProf;
};

void printEntry(staffTWB);

int main() {

string staffName;
int staffProf;

while (staffName != "done") {

cout << "Please enter a staff name(done to leave the program):" << endl;
getline(cin, staffName, '\n');
if (staffName == "done") {
break;
}
else {
cout << "Please enter the profession of " << staffName << "\n";
cin >> staffProf;
cin.ignore();
if (staffProf >= 1 && staffProf <= 4) {
printEntry(staffTWB);
}
else {
cout << "Wrong entry!\n";
cin.clear();
cin.sync();


}

}
}

void printEntry(staffTWB);
{
if (staffProf == 1)
cout << "Staff " << staffName << " is a Receptionist\n";
else if (staffProf == 2)
cout << "Staff " << staffName << " is a Administrator\n";
else if (staffProf == 3)
cout << "Staff " << staffName << " is a Nurse\n";
else if (staffProf == 4)
cout << "Staff " << staffName << " is a Doctor\n";
}
return 0;
}

It states that is occurs on the printEntry(staffTWB); line. What can I do to stop this error from ocurring?
void printEntry(staffTWB);

You have ; at the end of that line that shouldn't be there.
I then get this error

Compilation failed due to following error(s).

15 | int main() {
You've forgot a closing } at the end of the main function.
When posting formatted code, please use code tags so that the code is readable.

[code]
formatted code goes here
[/code]


There are various issues around usage of struct and defining and using functions. Consider:

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
#include <iostream>
#include <string>

struct staffTWB {
	std::string staffName;
	int staffProf {};
};

void printEntry(const staffTWB&);

int main() {
	staffTWB staff;

	while (staff.staffName != "done") {
		std::cout << "Please enter a staff name (done to leave the program):";
		std::getline(std::cin, staff.staffName);

		if (staff.staffName == "done")
			break;
		else {
			std::cout << "Please enter the profession of " << staff.staffName << ": ";
			std::cin >> staff.staffProf;

			if (staff.staffProf >= 1 && staff.staffProf <= 4)
				printEntry(staff);
			else {
				std::cout << "Wrong entry!\n";
				std::cin.clear();
			}
			std::cin.ignore();
		}
	}
}

void printEntry(const staffTWB& staff) {
	if (staff.staffProf == 1)
		std::cout << "Staff " << staff.staffName << " is a Receptionist\n";
	else if (staff.staffProf == 2)
		std::cout << "Staff " << staff.staffName << " is a Administrator\n";
	else if (staff.staffProf == 3)
		std::cout << "Staff " << staff.staffName << " is a Nurse\n";
	else
		std::cout << "Staff " << staff.staffName << " is a Doctor\n";
}


or as 'shortened code':

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
#include <iostream>
#include <string>

struct staffTWB {
	std::string staffName;
	int staffProf {};
};

void printEntry(const staffTWB&);

int main() {
	for (staffTWB staff; (std::cout << "Please enter a staff name (done to leave the program):") && std::getline(std::cin, staff.staffName) && staff.staffName != "done"; std::cin.clear(), std::cin.ignore()) {
		std::cout << "Please enter the profession of " << staff.staffName << ": ";
		std::cin >> staff.staffProf;

		if (staff.staffProf >= 1 && staff.staffProf <= 4)
			printEntry(staff);
		else
			std::cout << "Wrong entry!\n";
	}
}

void printEntry(const staffTWB& staff) {
	constexpr const char* names[4] {"Receptionist", "Administrator", "Nurse", "Doctor"};

	std::cout << "Staff " << staff.staffName << " is a " << names[staff.staffProf - 1] << '\n';
}

Last edited on
So how can I get the code to display like this:

Please enter a staff name("done" to leave the program):
John Lynch
Please enter the profession of John Lynch
1
Please enter a staff name("done" to leave the program):
Mary Cook
Please enter the profession of John Lynch
4
Please enter a staff name("done" to leave the program):
done
*********List of staffs********
Staff John Lynch is a receptionist
Staff Mary Cook is a doctor
*********End of List*********
You need to maintain a container of the entered data (eg a vector). Possibly something like:

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
#include <iostream>
#include <string>
#include <vector>

struct staffTWB {
	std::string staffName;
	int staffProf {};
};

void printEntry(const staffTWB&);

int main() {
	std::vector<staffTWB> staffs;

	for (staffTWB staff; (std::cout << "Please enter a staff name (done to leave the program):") && std::getline(std::cin, staff.staffName) && staff.staffName != "done"; std::cin.clear(), std::cin.ignore()) {
		std::cout << "Please enter the profession of " << staff.staffName << ": ";
		std::cin >> staff.staffProf;

		if (staff.staffProf < 1 || staff.staffProf > 4)
			std::cout << "Wrong entry!\n";
		else
			staffs.push_back(std::move(staff));
	}

	for (const auto& s : staffs)
		printEntry(s);
}

void printEntry(const staffTWB& staff) {
	static constexpr const char* names[4] {"Receptionist", "Administrator", "Nurse", "Doctor"};

	std::cout << "Staff " << staff.staffName << " is a " << names[staff.staffProf - 1] << '\n';
}

Topic archived. No new replies allowed.