Answer:
#include<cstdio>
#include<conio.h>
using namespace std;
float groceryamount(float cost, int quantity, float taxrate, float *costbefortax, float *taxamount, float *costaftertax);
int main()
{
float cost, taxrate, costbefortax, taxamount, costaftertax,a,b,c;
int quantity;
printf("enter the cost of product");
scanf("%f",&cost);
printf("enter the quantity of product that required");
scanf("%d",&quantity);
printf("enter the tax rate in percentage");
scanf("%f",&taxrate);
groceryamount(cost, quantity, taxrate, &costbefortax, &taxamount, &costaftertax);
printf("\nTotal amount before tax = %f", costbefortax );
printf("\n Total Tax Amount = %f", taxamount );
printf("\n Total Amount After Tax Deduction = %f", costaftertax );
getch();
}
float groceryamount(float cost, int quantity, float taxrate, float *costbefortax, float *taxamount, float *costaftertax)
{
float a,b,c;
a= cost * quantity;
b= a * (taxrate/100);
c= a - b;
*costbefortax=a;
*taxamount=b;
*costaftertax=c;
}
Explanation:
The program has six variable that have different data types. Therefore the function data type is void. I use cost, taxrate, costbefortax, taxamount and costaftertax in float as all these values could be in decimal. The quantity is usually in integer so I take it as int data type. cost before tax, tax amount and cost after tax has been calculated using function and returned to the main function.