
June 18th, 2009, 01:47 PM
#1
[Help]Pointers with Functions Problem!
I keep getting this error on line 39, as well as some others.
error C2296: '*' : illegal, left operand has type 'double (__cdecl *)(double *)'
I have no idea how to fix it, it gives me the same errors when I don't use the pointers and at this point I can't see a work around.
Any help at all would be appreciated.
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
double taxOne(double* grossIncome);
double taxTwo(double* grossIncome);
//double airTax(double taxOne, double taxTwo, double grossIncome);
int main()
{
char loopIndicator = 'Y';
int sinNum = 0;
double grossIncome = 0;
double* pgrossIncome = &grossIncome;
double airTax = 0;
while(loopIndicator == 'Y'  loopIndicator == 'y')
{
cout << "Enter your SIN number: ";
cin >> sinNum;
cout << "Enter your gross income: ";
cin >> grossIncome;
//calculation stuff goes here
if(grossIncome > 50000)
{
cout << "Total income tax is " << taxOne(&grossIncome);
airTax = taxOne * 0.07;
cout << endl << "Air tax is " << airTax;
}
else
{
cout << "Total income tax is " << taxTwo(&grossIncome);
}
cout << endl << "Would you like to enter another? Y/N: ";
cin >> loopIndicator;
if(loopIndicator == 'N'  loopIndicator == 'n')
{
break;
}
}//end while
return 0;
}//end main
//Function to compute income tax if grossIncome > 50000, tax is .47%
double taxOne(double* &grossIncome)
{
double result = &grossIncome * 0.47;
return result;
}//end function
//Function to compute income tax if grossIncome < 50000, tax is .44%
double taxTwo(double* &grossIncome)
{
double result = &grossIncome * 0.44;
return result;
}//end function

June 18th, 2009, 02:06 PM
#2
Re: [Help]Pointers with Functions Problem!
It would be easier if you pointed to a line that generated an error.
Code:
airTax = taxOne * 0.07;
taxOne is a function name. How can you multiply it by anything?
Vlad  MS MVP [2007  2012]  www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows  replacement windows manager for Visual Studio, and more...

June 18th, 2009, 02:43 PM
#3
Re: [Help]Pointers with Functions Problem!
Well, what I need this to do is :
Take taxOne(or taxTwo depending on the income), and multiply it by 0.07% to get the airTax value.

June 18th, 2009, 02:47 PM
#4
Re: [Help]Pointers with Functions Problem!
Reverting back to what I had before:
Code:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
double taxOne(double grossIncome);
double taxTwo(double grossIncome);
//double airTax(double taxOne, double taxTwo, double grossIncome);
int main()
{
char loopIndicator = 'Y';
int sinNum = 0;
double grossIncome = 0;
double airTax = 0;
while(loopIndicator == 'Y'  loopIndicator == 'y')
{
cout << "Enter your SIN number: ";
cin >> sinNum;
cout << "Enter your gross income: ";
cin >> grossIncome;
//calculation stuff goes here
if(grossIncome > 50000)
{
cout << "Total income tax is " << taxOne(grossIncome);
//airTax = taxOne * 0.07;
//cout << endl << "Air tax is " << airTax;
}
else
{
cout << "Total income tax is " << taxTwo(grossIncome);
}
cout << endl << "Would you like to enter another? Y/N: ";
cin >> loopIndicator;
if(loopIndicator == 'N'  loopIndicator == 'n')
{
break;
}
}//end while
return 0;
}//end main
//Function to compute income tax if grossIncome > 50000, tax is .47%
double taxOne(double grossIncome)
{
double result = grossIncome * 0.47;
return result;
}//end function
//Function to compute income tax if grossIncome < 50000, tax is .44%
double taxTwo(double grossIncome)
{
double result = grossIncome * 0.44;
return result;
}//end function
//Function to compute air tax
double airTax(double taxOne, double taxTwo, double grossIncome)
{
if(grossIncome > 50000)
{
double result = taxOne * 0.07;
return result;
}//end if
else
{
double result = taxTwo * 0.07;
return result;
}//end else
}//end function
How would i make my airTax function display? It gives me an error whenever I put the cout << airTax(taxOne, taxTwo, grossIncome).

June 18th, 2009, 02:52 PM
#5
Re: [Help]Pointers with Functions Problem!
Code:
cout << airTax(taxOne(grossIncome), taxTwo(grossIncome), grossIncome) << endl;
Kurt

June 18th, 2009, 03:02 PM
#6
Re: [Help]Pointers with Functions Problem!
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
This a Codeguru.com survey!
OnDemand Webinars (sponsored)
