C++ examples for Data Type:double
Program to calculate tax rate of 23%
#include <iostream> const double FAIR_TAX = 0.23f; double calculateTax(double); int main(int argc, const char *argv[]) { double dAmount = 0.0f; double dAmountTotal = 0.0f; while (dAmount != -1) { std::cout << "Enter expenses (-1 to quit): "; std::cin >> dAmount;/*from ww w .j a va2s . c o m*/ if (dAmount > 0) dAmountTotal += dAmount; } std::cout << "Total amount: " << dAmountTotal << std::endl; std::cout << "Tax: " << calculateTax(dAmountTotal) << std::endl; return 0; } // returns the tax rate double calculateTax(double baseAmount) { return baseAmount * FAIR_TAX; }