fork download
  1. #include <iostream>
  2.  
  3. int main() {
  4. const int DOLLAR = 100; //pennies per dollar
  5. const int RATE = 12; //in perecent
  6. int price = 0; //price of the product you are purchasing
  7. int total_price = 0;
  8. int cents = 0; //the amount of change left over
  9.  
  10. std::cout << "Please enter the price of the product you are purchasing($): ";
  11. std::cin >> price;
  12.  
  13. total_price = price * ( DOLLAR + RATE ); //using formula ( 1 + rate ) multiplied by 100
  14.  
  15. std::cout << "After tax you owe " << total_price << " cents." << std::endl;
  16.  
  17. cents = total_price % DOLLAR;
  18. total_price /= DOLLAR; //removing the cents
  19.  
  20. std::cout << "After tax you owe " << total_price << " dollars and " << cents << " cents." << std::endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 3344KB
stdin
1
stdout
Please enter the price of the product you are purchasing($): After tax you owe 112 cents.
After tax you owe 1 dollars and 12 cents.