142k views
4 votes
Write a C function which takes three parameters which are the cost for an item in a grocery store, the quantity to buy, and the tax percentage. The function should calculate and return the following values:

The cost before the tax amount(cost*quantity)
The tax amount(the cost before the tax amount* tax%/100
The cost with the tax amount( the cost before the tax amount+ the tax amount) for the item
(NOT A COMPLETE PROGRAM)

2 Answers

0 votes

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("\\Total amount before tax = %f", costbefortax );

printf("\\ Total Tax Amount = %f", taxamount );

printf("\\ 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;

}

Step-by-step 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.

User Naveen Kumar M
by
5.5k points
5 votes

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;

}

Step-by-step 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.
User Venkata Dorisala
by
5.9k points