Jnr Jnr - 2 months ago 5
C Question

Getting invalid operands to binary + as well as previous declarition errors

As far as I know, I'm not using multiple operators, but I can't get my program to work.

I am pretty sure I have my functions alright, except perhaps the call but I don't know how to apply it to specific codes.

#include<stdio.h>

void inputTotalSales(float *);
void calculateTaxes(float *, float *, float *, float *);
void displayTaxes(float *, float *, float *);

int main()
{
float totalSales, salesTax, stateTax, countyTax;

inputTotalSales(& totalSales);
calculateTaxes(&totalSales, & salesTax, & stateTax, & countyTax);
displayTaxes(& salesTax, &stateTax, &countyTax);

return 0;
}

void inputTotalSales(float *totalSalesp)
{
printf("Please enter your total sales for the month: ");
scanf("%f", totalSalesp);
printf("\nYour monthly sales total is %.2f", *totalSalesp);

}

void calculateTaxes (float *totalSalesp, float *salesTaxp, float *stateTaxp,float *countyTaxp )
{
salesTaxp = (totalSalesp * .06);
stateTaxp = (totalSalesp * .04);
countyTaxp = (totalSalesp * .02);
}

void displayTaxes (float salesTax, float stateTax, float countyTax)
{
printf("\nYour monthly sales tax is %.2f.", salesTax);
printf("\nYour monthly state tax is %.2f.", stateTax);
printf("\nYour monthly county tax is %.2f.", countyTax);
}


Also, any books you could recommend would be great! My teacher never had a book he liked so we never we're assigned one... and I'm struggling. Any other good sites as well would be greatly appreciated!

Answer

There are some problems in you code

1) calculateTaxes function you are passing pointers and you are trying to multiply the pointers with a number, instead you should multiply the value of these pointers with the numbers.

2) You have declared displayTaxes with pointers(float *) and while defining the function you are using a different declaration with only floats.

Here is the code without these issues:

void inputTotalSales(float *);
void calculateTaxes(float *, float *, float *, float *);
void displayTaxes(float , float , float );
int main()
{

 float totalSales, salesTax, stateTax, countyTax;

    inputTotalSales(& totalSales);
    calculateTaxes(&totalSales, & salesTax, & stateTax, & countyTax);
    displayTaxes(salesTax, stateTax, countyTax);

 return 0;
}



void inputTotalSales(float *totalSalesp)
{
   printf("Please enter your total sales for the month: ");
   scanf("%f", totalSalesp);
   printf("\nYour monthly sales total is %.2f", *totalSalesp);

}

void calculateTaxes (float *totalSalesp, float *salesTaxp, float *stateTaxp,float     *countyTaxp )
{
   *salesTaxp = (*totalSalesp * .06);
   *stateTaxp = (*totalSalesp * .04);
   *countyTaxp = (*totalSalesp * .02);
}


void displayTaxes (float  salesTax, float  stateTax, float  countyTax)
{
     printf("\nYour monthly sales tax is %.2f.", salesTax);
     printf("\nYour monthly state tax is %.2f.", stateTax);
     printf("\nYour monthly county tax is %.2f.", countyTax);
}