C++程式計算原始價格和淨價的GST


給定原始成本和淨價作為輸入,任務是計算GST百分比並顯示結果。

GST代表商品和服務稅。它始終包含在產品的淨價中,在計算GST百分比之前,我們需要計算GST金額,為此有現成的公式。

淨價 = 原始成本 + GST金額

GST金額 = 淨價 – 原始成本

GST百分比 = (GST金額 * 100) / 原始成本

GST%公式 = (GST金額*100) / 原始成本

示例

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 %

給定程式中使用的方案如下

  • 將淨價和原始成本作為輸入。
  • 應用給定的公式計算GST百分比。
  • 顯示結果。

演算法

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

示例

 即時演示

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;
}

輸出

如果我們執行以上程式碼,它將生成以下輸出。

GST amount is = 25.00 %

使用C語言

示例

 即時演示

#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;
}

輸出

如果我們執行以上程式碼,它將生成以下輸出。

GST amount is : 25.00

更新於: 2019年10月18日

1K+ 瀏覽量

開啟您的職業生涯

透過完成課程獲得認證

開始學習
廣告