Help with methods and pointers GROSSPAY

I am having trouble getting my calcGross Method. I can't get it to multiply a int* by a double* to go into a double. I am also getting an error on line 9 at the beginning of my second prototype saying that I need a bracket {

Thank you for Your help!
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
52
// Gross Pay.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include "pch.h"
#include <iostream>
#include <iomanip>
using namespace std;
int getHoursWorked()
double getPayRate()
double calcGross(int*,double*)

int main()
{

	int HOURS{ 0 };
	double pRate{ 0 };
	double GROSSPAY{ 0 };
    std::cout << "To calculate Gross Pay first enter hours worked.\n:"; 

	HOURS = getHoursWorked();
	pRate = getPayRate();
	GROSSPAY = calcGross(&HOURS, &pRate);




}

int getHoursWorked()
{
	int hours1{ 0 };
	cin >> hours1;
	return hours1;
}

double getPayRate()
{
	double rate{ 0 };
	cout << "\n Next enter the Pay Rate.\n: ";
	cin >> rate;
	return rate;
}

double calcGross (int* HOURS, double*pRate)
{
	int HOURS2{ 0 };
	HOURS2 = HOURS;
	double GROSSPAY{ 0 };
	GROSSPAY = HOURS *pRate;
	return GROSSPAY;
}
Last edited on
Your function declaration prototypes at line 8, 9 and 10 all need a semi-colon.

8
9
10
int getHoursWorked();
double getPayRate();
double calcGross(int*,double*);


Without them the compiler thinks you are trying to define the functions, actually just the first one on line 8, the reason why you get the error for the missing bracket at line 9.
Last edited on
1
2
3
4
double calcGross (int* HOURS, double*pRate)
{
	int HOURS2{ 0 };
	HOURS2 = HOURS;


This code. HOURS is a pointer. HOURS2 is an int. One of them represents a memory address. One of them represents a number. What you're doing makes no sense at all.

I can't get it to multiply a int* by a double* to go into a double

That doesn't make any sense. You should multiply an int by a double. Trying to multiply two pointers together makes no sense.
Thank you that fixed my error at the top.
I'm trying to multiply HOURS by pRate to get GROSSPAY inside of the calcGross method.
I'm trying to multiply HOURS by pRate to get GROSSPAY inside of the calcGross method.

You have to multiply the values the pointers point to, not multiply the addresses the pointers hold.
1
2
3
4
double calcGross (int* HOURS, double* pRate)
{
   return ((*HOURS) * (*pRate));
}

Using references can also work:
1
2
3
4
double calcGross (int& HOURS, double& pRate)
{
   return (HOURS * pRate);
}

Why are you passing Plain Old Data types (int, double) by pointer (or reference) anyway? You are not modifying the passed parameters, and passing POD types by value doesn't have the performance hit that passing complex data types like classes and STL containers can have.
1
2
3
4
double calcGross (int HOURS, double pRate)
{
   return (HOURS * pRate);
}

You are over-complicating what should be a simple coded function. HOURS2 and GROSSPAY are two function scoped variables that really don't serve much purpose.

Especially HOURS2.

Last edited on
If you want to use a value that a pointer points to, then you must dereference the pointer.


Why do you use pointers at all? "Homework makes me"?
Thank you for the help it's running now!
Topic archived. No new replies allowed.