Respuesta :
Answer:
struct item
{
float previousCost;
float taxAmount;
float updatedCost;
} itemObject;
void calculation(int cost,int quantity,float tax)
{
struct item *itemPointer=&itemObject;
itemPointer->previousCost=(cost) * (quantity);
itemPointer->taxAmount=itemPointer->previousCost * (tax/100);
itemPointer->updatedCost=itemPointer->previousCost+itemPointer->taxAmount;
}
Explanation:
- Define a structure called item that has 3 properties namely previousCost, taxAmount and updatedCost.
- The calculation function takes in 3 parameters and inside the calculation function, make a pointer object of the item structure.
- Calculate the previous cost by multiplying cost with quantity.
- Calculate the tax amount by multiplying previous cost with (tax / 100).
- Calculate the previous cost by adding previous cost with tax amount.
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.