calling arguments

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
int main()
{
	float hours, rate, wage;

	void Earnings(float h, float r);

	cout << "Enter the total Weekly hours: ";
	cin >> hours;
	cout << "Enter the employee's hourly rate: ";
	cin >> rate;

	cout << "\nIn the main() function,";
	cout << "\n\tWeekly Hours = " << hours;
	cout << "\n\tSalary = $" << rate; 
	cout << "\n\tWeekly Salary: $" << hours * rate;
	cout << "\nCalling the Earnings() function";

	Earnings(hours, rate);

	cout << "\n\nAfter calling the Earnings() function, "
		 << "in the main() function,";
	cout << "\n\tWeekly Hours = " << hours;
	cout << "\n\tSalary = " << rate;
	cout << "\n\tWeekly Salary: " << hours * rate;

	return 0;
}

void Earnings(float thisWeek, float salary)
{
	cout << "\n\nIn the Earnings() function,"; 
	cout << "\n\tWeekly Hours = " << thisWeek;
	cout << "\n\tSalary = " << salary;
	cout << "\n\tWeekly Salary= " << thisWeek * salary;
}


i saw this sample code on a website. i am confued. when this code defines a function called void Earnings, it uses (float thisWeek, float salary) parameter, but when it calls the function in the main, it uses (float h, float r), how does the compiler know that they are not 2 difference functions?

also, Earnings(hours, rate);, this line in the middle. how come this line doesnt need to use void Earning?

sorry i am an absolute beginner.
when this code defines a function called void Earnings

No, the function's name is just "Earnings". void is the return type (void just indicates that the function does not actually return anything).

it uses (float h, float r), how does the compiler know that they are not 2 difference functions?

Because the parameter names are not part of the function signature, the compiler does not care what you name them. In fact, you don't need to specify any parameter names at all.

how come this line doesnt need to use void Earning?

You only specify the return type when doing a function declaration/definition.
However, that line just calls the function.

And if you cannot execute ./configure, that either means there's no configure script in the current directory or it's missing executable rights.
Last edited on
Topic archived. No new replies allowed.