• We've upgraded our forums. Please post any issues/requests in this thread.

Another C++ Error, an "operand has type double...' "

Joined
Sep 5, 2007
Messages
488 (0.13/day)
Likes
47
System Name HAL_9017
Processor Intel i7 7700k
Motherboard MSI z270 Gaming M7
Cooling Corsair H115i
Memory GSkill 32GB DDR4-3000 Trident-Z RGB
Video Card(s) NVIDIA 1080GTX FE w/ EVGA Hybrid Water Cooler
Storage Samsung EVO 960 M.2 SSD 500Gb
Display(s) Dell U2713
Case In Win 805i
Power Supply CORSAIR RM750
Mouse Razer Mamba TE
Keyboard Corsair Strafe MX Silent RGB
#1
Hello Agian everyone.

I'm not to sure what could be doing this, as to me, it looks right. This is another assignment for entry C++. I know I sound like a newb asking for help agian, but then agian, what are forums for at time lie this?

Now, I have to use value returning functions in this assignment. I need to have the functions as main(), getHoursWorked(), getPayRate(), and calcGross() all together to calculate someones paycheck for the week.

So this sounds like a simple "Pay = hours * rate", just a little overdone (if you ask me. Then again, I don;t know better at this point, so if I'm jumping the gun, please let me know)

So I get all my kinks worked out, except this one line where I do the calculations for calcGross(). I have 2 errors from my build log. They say this:

error C2296: '*': illegal, left operand has type 'double(_cdecl*)(void)'
error C2297: '*': illegal, right operand has type 'double(_cdecl*)(void)'



Now, I'm not sure why I'm getting this. My arithimtic setup looks correct to me, so why would I get this?

I'm using Microsoft C++ Visual Studio Express 2005 for reference.

Now for the moment of joy:
Thank you all for helping.

P.S. - I was not sure to post this in my last thread, or make a new one. I figured, well, new problem and situation, which altogether is a different topic, so new thread. If I am wrong, pleas correct me too.

//Lab 3 by <<<<<< ENTER NAME HERE >>>>>>>>>
//ITCS 1214

#include <iostream>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::setprecision;

//function pronotypes
double getHoursWorked();
double getPayRate();
double calcGross();

int main()
{
//input variables
double totalPay = 0.0;

totalPay = calcGross();
cout << fixed << setprecision(2) << "Total Pay for this week is: $" << totalPay << endl;


return 0;
}//end of main function



//******function definitions******



double getHoursWorked()
{
//variables for hours worked
double hoursWorked = 0.0;
cout << "How many hours did the employee work this week?: ";
cin >> hoursWorked;
return hoursWorked;
}//end of getHoursWorked



double getPayRate()
{
double payRate = 0.0;

cout << "What is the employee's payrate?: $";
cin >> payRate;
return payRate;
}//end getPayRate function



double calcGross(double hoursWorked, double payRate)
{
double gross = 0.0;
gross = (getHoursWorked) * (getPayRate);
return gross;
}//end calcGross function
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#2
Since you are calling functions shouldn't this line in "calcGross()" look like ...

gross = getHourseWorked() * getPayRate();

Not great with C++, so just a guess. You need to include the parenthesis in C# when calling a function.
I think when you exclude the parenthesis you are accessing a pointer to the function instead of calling it.
Or something like that :D
 
Joined
Sep 5, 2007
Messages
488 (0.13/day)
Likes
47
System Name HAL_9017
Processor Intel i7 7700k
Motherboard MSI z270 Gaming M7
Cooling Corsair H115i
Memory GSkill 32GB DDR4-3000 Trident-Z RGB
Video Card(s) NVIDIA 1080GTX FE w/ EVGA Hybrid Water Cooler
Storage Samsung EVO 960 M.2 SSD 500Gb
Display(s) Dell U2713
Case In Win 805i
Power Supply CORSAIR RM750
Mouse Razer Mamba TE
Keyboard Corsair Strafe MX Silent RGB
#3
Tried the parenthesis, and got this:


 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#4
That's because you are declaring calcGross with two input parameters and not calling it with any in main().

Since you are calling the two functions from within calcGross, just declare it as
Code:
double calcGross()
{
    double gross = 0.0;
    gross = getHoursWorked() * getPayRate();
    return gross;
}
 
Last edited:
Joined
Sep 5, 2007
Messages
488 (0.13/day)
Likes
47
System Name HAL_9017
Processor Intel i7 7700k
Motherboard MSI z270 Gaming M7
Cooling Corsair H115i
Memory GSkill 32GB DDR4-3000 Trident-Z RGB
Video Card(s) NVIDIA 1080GTX FE w/ EVGA Hybrid Water Cooler
Storage Samsung EVO 960 M.2 SSD 500Gb
Display(s) Dell U2713
Case In Win 805i
Power Supply CORSAIR RM750
Mouse Razer Mamba TE
Keyboard Corsair Strafe MX Silent RGB
#5
That's because you are declaring calcGross with two input parameters and not calling it with any.

Since you are calling the two functions from within calcGross, just declare it as
Code:
double calcGross()
{
    double gross = 0.0;
    gross = getHoursWorked() * getPayRate();
    return gross;
}
Kreij, I love you so much.

I tweeked that and my main () and finally got it. Now I see what my error was. I was treating the calcGross like an a magic task, and not a value returning function like getHours and getRate.

I guess what you suggested just pushed me to fix it. You may have nudged me answer, but it helped me to understand my error and learn the concept. BAM!! Once agian, learning has occured. Thank you so much, and here is the pretty result:

//Lab 3 by
//ITCS 1214

#include <iostream>
#include <iomanip>

using std::cin;
using std::cout;
using std::endl;
using std::fixed;
using std::setprecision;

//function pronotypes
double getHoursWorked();
double getPayRate();
double calcGross();

int main()
{
//input variables
double totalPay = 0.0;

totalPay = calcGross();

cout << fixed << setprecision(2) << "Total Pay for this week is: $" << totalPay << endl;


return 0;
}//end of main function

//******function definitions******
double getHoursWorked()
{
//variables for hours worked
double hoursWorked = 0.0;
cout << "How many hours did the employee work this week?: ";
cin >> hoursWorked;
return hoursWorked;
}//end of getHoursWorked

double getPayRate()
{
double payRate = 0.0;

cout << "What is the employee's payrate?: $";
cin >> payRate;
return payRate;
}//end getPayRate function

double calcGross()
{
double gross = 0.0;
gross = getHoursWorked() * getPayRate();
return gross;
}//end calcGross
 
Last edited:

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#6
If you want to lighten the code a bit consider the following ...

Code:
double calcGross()
{
    double gross;  // no need to give it a value
    return gross = getHoursWorked() * getPayRate();
}
Saves a little typing !

also ...
Code:
int main()
{
    cout << fixed << setprecision(2) << "Total Pay for Week = $" << calcGross() << endl;
    return 0;
}
No need to have totalPay variable at all then.

Good job !! :toast:
 

Kreij

Senior Monkey Moderator
Staff member
Joined
Feb 6, 2007
Messages
13,817 (3.48/day)
Likes
5,524
Location
Cheeseland (Wisconsin, USA)
Processor Intel Core 2 Quad QX9650 Extreme @ 3.0 GHz
Motherboard Asus Rampage Formula
Cooling ZeroTherm Nirvana NV120 Premium
Memory 8GB (4 x 2GB) Corsair Dominator PC2-8500
Video Card(s) 2 x Sapphire Radeon HD6970
Storage 2 x Seagate Barracuda 320GB in RAID 0
Display(s) Dell 3007WFP 30" LCD (2560 x 1600)
Case Thermaltake Armor w/ 250mm Side Fan
Audio Device(s) SupremeFX 8ch Audio
Power Supply Thermaltake Toughpower 750W Modular
Software Win8 Pro x64 / Cat 12.10
#7
Oh ... and a couple of comments on what you posted ...
I know I sound like a newb asking for help agian, but then agian, what are forums for at time like this?
That is exactly what we are here for. Never be afraid to ask. No question is too basic.
No one is born knowing how to program, and you have to start somewhere.

P.S. - I was not sure to post this in my last thread, or make a new one. I figured, well, new problem and situation, which altogether is a different topic, so new thread. If I am wrong, pleas correct me too.
New thread for new problem is fine as long as you are not just making a new thread to continue an existing problem

Kreij, I love you so much.
If you are a guy ... we have may have problems.
If you are a girl ... Mrs. Kriej may have problems
:roll: