fork download
  1. /******************************************************************************************
  2. * Name: Marcelo Vargas
  3. * Chapter 2 Homework
  4. * Class: CSC5
  5. * #3
  6. *
  7. * Sales Tax
  8. *
  9. * This program computes the total sales tax on a $52 purchase with a 4% state tax rate
  10. * and a 2% country tax rate
  11. *__________________________________________________________________________________________
  12. *INPUT
  13. * price :the amount of the purchase ($52)
  14. * stateTaxRate :the tax % of the state tax (%4)
  15. * countryTaxRate :the tax % of the country tax (%2)
  16. *
  17. * OUTPUT
  18. * statetax :sum of state tax
  19. * countrytax :sum of country tax
  20. * total :sum of price, statetax, and countrytax
  21. ******************************************************************************************/
  22. //importing "iostream" & "iomanip" from stream library
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. int main(){
  28. // Declare variables
  29. float price; //Inputprice of the purchase
  30. float stateTaxRate; //Input statetax peercentage
  31. float countryTaxRate; //Input countrytax percentage
  32. float statetax; //Output of state tax
  33. float countrytax; //Output of country tax
  34. float totaltax; //Output of total tax
  35.  
  36. price = 52.0;
  37. stateTaxRate = 0.04;
  38. countryTaxRate = 0.02;
  39.  
  40. //calculate the taxes
  41. statetax = price * stateTaxRate;
  42. countrytax = price * countryTaxRate;
  43. totaltax = statetax + countrytax;
  44.  
  45. //outputs the total of the calculations
  46. cout << fixed << setprecision(2);
  47. cout << "State sales tax: $" << statetax << endl;
  48. cout << "contry Sales Tax: $" << countrytax << endl;
  49. cout << "Total Sales Tax: $" << totaltax << endl;
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
State sales tax: $2.08
contry Sales Tax: $1.04
Total Sales Tax: $3.12