C++ program to calculate GST from original and net prices

C++Server Side ProgrammingProgramming

Given with the original cost and net price as an input and the task is to calculate the GST percentage and display the result

GST stands for Goods and Service task. It is always included in the Net price of the product and before calculating the GST percentage we need to calculate GST amount and for that there are formulas available

Netprice = originalcost + GSTAmount

GSTAmount = Netprice – original_cost

GST_Percentage = (GSTAmount * 100)/ originalcost

GST % formula = (GSTAmount*100) / originalcost

Example

Input-: cost = 120.00
   price = 150.00
Output-: GST amount is = 25.00 %
Input-: price = 120.00
   cost = 100.00
Output-: GST amount is = 20.00 %

Approach used in the given program is as follows

  • Take the input as net price and original cost
  • Apply the formula given to calculate GST percentage
  • Display the result

Algorithm

Start
Step 1-> declare function to calculate GST
   float GST(float cost, float price)
   return (((price - cost) * 100) / cost)
step 2-> In main()
   set float cost = 120
   set float price = 150
   call GST(cost, price)
Stop

Example

 Live Demo

Using c++
#include <iostream>
using namespace std;
//function to calculate GST
float GST(float cost, float price) {
   return (((price - cost) * 100) / cost);
}
int main() {
   float cost = 120.00;
   float price = 150.00;
   cout << "GST amount is = "<<GST(cost, price)<<" % ";
   return 0;
}

Output

IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT

GST amount is = 25.00 %

Using C

Example

 Live Demo

#include <stdio.h>
//function to calculate GST
float GST(float cost, float price) {
   return (((price - cost) * 100) / cost);
}
int main() {
   float cost = 120;
   float price = 150;
   float gst = GST(cost, price);
   printf("GST amount is : %.2f ",gst);
   return 0;
}

Output

IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT

GST amount is : 25.00
raja
Published on 18-Oct-2019 14:42:28
Advertisements