[Help]Pointers with Functions Problem!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [Help]Pointers with Functions Problem!

  1. #1
    Join Date
    Jun 2009
    Location
    Canada
    Posts
    18

    [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

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    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:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  3. #3
    Join Date
    Jun 2009
    Location
    Canada
    Posts
    18

    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&#37; to get the airTax value.

  4. #4
    Join Date
    Jun 2009
    Location
    Canada
    Posts
    18

    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).

  5. #5
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: [Help]Pointers with Functions Problem!

    Code:
    cout << airTax(taxOne(grossIncome), taxTwo(grossIncome), grossIncome) << endl;
    Kurt

  6. #6
    Join Date
    Jun 2009
    Location
    Canada
    Posts
    18

    Re: [Help]Pointers with Functions Problem!

    TY Zuk! Big help, <3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center