Calculating salary (feedback on code)

Hey all, I getting some practice using functions and would like some feedback on my code. I wrote this to calculate weekly pay, monthly pay, and annual pay.

I'm wondering if

a)what I am doing is correct (if I'm using functions correctly, structure etc.)
b)I can improve on anything

I have written this without using functions as well but I want to practice using functions specifically using cin and calling functions within functions.

Thanks!

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
 // calculating salary
#include <iostream>
using namespace std;

void display(int hrpay, int weekhr);
int week(int hrpay,int weekhr);
int month(int hrpay, int weekhr);
int annual(int hrpay, int weekhr);


int hrpay, weekhr;

int main()
{
	cout << "Please enter hourly wage: \n";
	cin >> hrpay;
	cout << "Please enter weekly working hours: \n";
	cin >> weekhr;

	display(hrpay, weekhr);
	return 0;
}

void display(int hrpay, int weekhr)
{
	cout << "Your weekly pay is $" << week(hrpay, weekhr) << endl;
	cout << "Your monthly pay is $" << month(hrpay, weekhr) << endl;
	cout << "Your annual pay is $" << annual(hrpay, weekhr) << endl;
}


int week(int hrpay, int weekhr)
{
	int weeklypay = hrpay * weekhr;
	int monthlypay = hrpay * (weekhr * 4);
	return monthlypay;
	return weeklypay;
}

int month(int hrpay, int weekhr)
{
	int monthlypay = hrpay * (weekhr * 4);
	return monthlypay;
}

int annual(int hrpay, int weekhr)
{
	int annualpay = 12 * (hrpay * (weekhr * 4));
	return annualpay;
}
Last edited on
Why is your week function calculating monthly pay? You have a month function for that no?

You also can't return 2 things from a function like that.

1
2
3
return monthlypay;
	return weeklypay;
}


Doesnt work.
ahh thank you. I think I was testing to see if it works and forgot it in there
Topic archived. No new replies allowed.