fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Set up variables
  6. int coffeePurchased = 0;
  7. double coffeePrice = 0.0;
  8. char salesTaxInfo = ' ';
  9.  
  10.  
  11. double coffeeCost = 0.0;
  12. double salesTaxRate = .035;
  13. double salesTaxAmount = 0.0;
  14.  
  15. double amountOwed= 0.0;
  16.  
  17. // Take in information from user
  18. std::cout << "Enter the amount of coffee purchased: ";
  19. std::cin >> coffeePurchased;
  20. std::cout << "Enter the price of coffee: ";
  21. std::cin >> coffeePrice;
  22. std::cout << "Enter if sales tax should be charged( y or n): ";
  23. std::cin >> salesTaxInfo;
  24. // calculate cost of coffee
  25. coffeeCost = coffeePurchased * coffeePrice;
  26. // Determine if sales tax is to be added
  27. if( salesTaxInfo == 'y')
  28. salesTaxAmount = coffeeCost * salesTaxRate;
  29. amountOwed = coffeeCost + salesTaxAmount;
  30. if(salesTaxInfo == 'n')
  31. amountOwed = coffeeCost;
  32.  
  33. // Display the amount owed
  34. std::cout << "The Customer owes: $" << amountOwed<< std::endl;
  35. return 0;
  36. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Enter the amount of coffee purchased: Enter the price of coffee: Enter if sales tax should be charged( y or n): The Customer owes: $0