### Re: Function to calculate Tax

Hi
I am writing a function where is calculates TAX based on AGE and Income.
The error I get is below and I have been researching to find an explanation but
none seem to fit my issue
Error: [Error] ISO C++ forbids comparison between pointer and integer [-fpermissive]

I am sure how I use the function in main is also not correct

Any help or hint would be very much appreciated

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include using namespace std; void Cal_Print(int age[], int INcome[]){ int tax; if (age<55&&INcome <= 10000){ tax = 0; } else if (age<55 && INcome >10000 && INcome<=50000){ tax = INcome*10/100; } else if (age<55 &&INcome >50000 && INcome <=100000){ tax =INcome*20/100; } else if (age<55&&INcome >100000){ tax = INcome*30/100; } else if (age>=55 && age<80&&INcome <= 20000){ tax = 0; } else if (age>=55&&age<80&&INcome >20000 && INcome<=70000){ tax = INcome*10/100; } else if (age>=55&&age<80&&INcome >70000 && INcome<=150000){ tax =INcome*20/100; } else if (age>=55&&age<80&&INcome >150000){ tax = INcome*30/100; } else if (age >= 80){ tax = 0; } } int main() { int fnpfNbr[6] = {12345, 12361, 34763, 11224, 54129, 10717}; int size=6; int Age[6] = {24, 19, 47, 50, 35, 26}; char lastname_initial[6] = {'F', 'B', 'H', 'H', 'R', 'B'}; int Income[] = {40000, 20000, 100000, 35000, 75000, 28000}; int Tax[6]; Cal_Print(Age[], Income[]); for (int i =0; i < size; i++){ cout <
 ``12345`` ``````void Cal_Print(int age[], int INcome[]){ int tax; if (age<55&&INcome <= 10000){ tax = 0; }``````

Please note that `int INcome[]` is an array. You have to access array by index to access the desired integer element.

Without index, you cannot compare it with anything.
Noted with thanks
Hi Mantorr22,
I have Worked on the code and now it did compile BUT the tax calculated is not as per programmed.

I have tried other ways via research...unfortunately I am getting nowhere

Any help would very much appreciated

My compiled code below:
#include <iostream>
using namespace std;

//Tax calculation function
void Cal_Tax(int A, int I){//A for Age, I for Income (Parameters)
int tax;
if (A<55&&I <= 10000){
tax = 0;
}
else if (A<55 && I >10000 && I<=50000){
tax = I*10/100;
}
else if (A<55 &&I >50000 && I <=100000){
tax =I*20/100;
}
else if (A<55&&I >100000){
tax = I*30/100;
}

else if (A>=55 && A<80&&I <= 20000){
tax = 0;
}
else if (A>=55&&A<80&&I >20000 && I<=70000){
tax = I*10/100;
}
else if (A>=55&&A<80&&I >70000 && I<=150000){
tax =I*20/100;
}
else if (A>=55&&A<80&&I >150000){
tax = I*30/100;
}

else if (A >= 80){
tax = 0;
}
}

int main()
{

int FNPFNbr[6] = {12345, 12361, 34763, 11224, 54129, 10717};
int SIZE=6;
int AGE[6] = {24, 19, 47, 50, 35, 26};
char LASTNAME_initial[6] = {'F', 'B', 'H', 'H', 'R', 'B'};
int INCOME[6] = {40000, 20000, 100000, 35000, 75000, 28000};
double TAX[6];

Cal_Tax(AGE[0], INCOME[0]);
cout <<"\nLastname(initial)"<<"\t"<<"FNPF#"<<"\t"<<"AGE"<<"\t"<<"Income"<<"\t"<<"Tax\n";
cout <<"----------------"<<"\t"<<"------"<<"\t"<<"---"<<"\t"<<"------"<<"\t"<<"-----\n";
for (int i =0; i < SIZE; i++){
cout <<LASTNAME_initial[i]<<"\t\t\t"<<FNPFNbr[i]<<"\t"<<AGE[i]<<"\t"<<INCOME[i]<<"\t"<<TAX<<"\n";
}

return 0;
}
What did you expect, what did you get?

\t"<<"Tax\n";

once again, you have array without []

you also do not seem to be filling tax[I] in with any values that I see....
Last edited on
Hi jonnin,

Sorry, typo error! Yes, i did code tax[i]..

My code was the function to base on the INCOME array + the AGE array to auto compute the TAX array

For example:
Income 40,000, tax as coded should be 4000 (10% of income). However, it is giving me 2.65941e-307
Or 20,000, tax should be 2000 but it is giving me 1.50783e-307

My function coding is not correct and my problem is I am all confused correcting it.
If you need some hints, you can have a look at the following example based on your code:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````#include #include //Tax calculation function double cal_Tax(int age, int income); int main() { int age[] = {24, 19, 47, 50, 35, 26}; int income[] = {40000, 20000, 100000, 35000, 75000, 28000}; int size = sizeof(age) / sizeof(int); double* tax = new double[size]; for(int i=0; i

Just like I said...

tax the array in main isn't populated. its full of random values.

cal-tax fills in the local variable tax, but it never bridges the gap.

you need something like this..

double cal_tax(...)
{
...
return tax;
}

...
for(...)
tax[i] = cal_tax(..stuff);

as a side note, I don't think any of the values should be int, but double instead. That is your design choice, but you may have problems with it if you happen to calculate x/y where it becomes zero unintentionally and you may get odd roundoff errors.
Last edited on
Thank you very much Enoizat and Jonnin. After those hint and example, it now workout for me.

Have a great day!
Topic archived. No new replies allowed.