Feb 2, 2015 at 6:31pm UTC
Solved
Last edited on Feb 3, 2015 at 2:45am UTC
Feb 2, 2015 at 6:41pm UTC
In getSalary() function you want to use hours variable that doesn't have value, 'cuz you didn't assign any to it.
Feb 2, 2015 at 7:05pm UTC
How can I get the hours and rate values to carry over from the previous functions?
Feb 2, 2015 at 7:17pm UTC
pass by reference.
http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
edit: but you also need to sort out your logic of what you are passing to what.
e.g.:
1 2 3 4 5 6
void getSalary (double amount)
{
double hours;
double rate;
amount = hours * rate;
..
You are passing in 'amount', so why the hell try and calculate it? Unless you aren't passing in amount, then you should call it something else.
stuff like that.
Last edited on Feb 2, 2015 at 7:22pm UTC
Feb 2, 2015 at 10:43pm UTC
Okay, pass by reference. I just can't understand this..
I don't want to ask somebody to do my homework for me, so could somebody just apply this to the first functions on my code as an example?
I really appreciate it.
Feb 2, 2015 at 11:06pm UTC
something like this;
1 2 3 4 5
void getHours (double & hours){
cout << " Enter the hours worked. " << endl;
cin >> hours;
cout << endl;
}
then you call it this way;
1 2
double hours;
getHours(hours);
If you didn't have reference yet you should do it like so:
1 2 3 4 5 6 7
double getHours (){
double hours;
cout << " Enter the hours worked. " << endl;
cin >> hours;
cout << endl;
return hours;
}
Then you call it:
double hours = getHours();
Last edited on Feb 2, 2015 at 11:09pm UTC
Feb 3, 2015 at 1:16am UTC
Hey Hardew, thanks for the response, but it's not working for me.
Could you paste it into the whole code and then I could see if I still get the same errors?
Feb 3, 2015 at 2:02am UTC
Is this want you wanted to do?
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
#include <iostream>
using namespace std;
void getHours(double &);
void getRate(double &);
void getSalary(double , double ); // if it's your payCheck() function, it should return value according to your first post
int main() {
double rate;
double hours;
getHours(hours);
getRate(rate);
getSalary(hours, rate);
cin.get();
cin.get();
return 0;
}
void getHours(double & hours) {
cout << " Enter the hours worked. " << endl;
cin >> hours;
cout << endl;
}
void getRate(double & rate) {
cout << " Enter the rate per hour at which you get paid." << endl;
cin >> rate;
cout << endl;
}
void getSalary(double hours, double rate) {
double amount;
amount = hours * rate;
if (hours > 40)
amount = hours * (rate * 1.5); // braces not needed
cout << " The total salary is: " << amount << endl;
}
Last edited on Feb 3, 2015 at 2:06am UTC
Feb 3, 2015 at 2:44am UTC
That's working.. Thanks so much hardew, I will review this, my coding definitely needs work. :P
Feb 3, 2015 at 9:48am UTC
can you put your original code back please?