What am I doing wrong?

write the function void get_emp_rec(int &id, double &prate, double &hours) that reads an employee's id number, pay rate and number of hours with an appropriate message. It returns the ID, pay rate, and the number of hours using the reference parameters id, prate, and hours, respectively.

1
2
3
4
5
6
7
8
9
10
11
12
void get_emp_rec(int &id, double &prate, double &hours)
{
     double rate, hour;
     int ID= 0;
     cout << "Enter employee ID:";
     cin >> id; 
     cout  << "Enter payrate:";
     cin  >> prate;
     cout  <<  "Enter the number of hours worked:";
     cin  >> hours;
     return (ID, rate, hour);
}
You cannot return an expression from a function with return type void.

Your code looks alright, just remove the return statement since you are using references. Also please remove using namespace std; from your global scope. If you really have to, put it in your function's scope.

However, it's still up to you to make "an appropriate message".
Than how would I return the ID, payrate and number of hours worked?
You're effectively already doing that. When you modify a reference, you also modify the variable it's referencing.

Example :

1
2
3
4
5
6
7
8

int main() {
	int var = 10;
	int& ref = var; // reference of var
	ref = 20; // var is now 20.
	return 0;
}


What your instructor/book meant to say is something around the lines of : "It should take three references as parameters to allow the user to modify their values".
Topic archived. No new replies allowed.