fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH4 HW Q:5
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Software Sales
  6.  *
  7.  *********************
  8.  *
  9.  * A software company sells a package that retails for $99. discounts
  10.  * are given according to the following rules of the company:
  11.  * 10-19 units = 20% discount
  12.  * 20-49 units = 30% discount
  13.  * 50-99 units = 40% discount
  14.  * 100+ units = 50% discount
  15.  *
  16.  * INPUT
  17.  * units : Number of units sold
  18.  *
  19.  * OUTPUT
  20.  * totalCost : Total cost of the purchase
  21.  *
  22.  ****************************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. const double PRICE = 99.0;
  31.  
  32. int units;
  33. double discount = 0.0;
  34. double totalCost;
  35.  
  36. cout << "Enter the number of units sold: ";
  37. cin >> units;
  38.  
  39. // Input validation
  40. if (units <= 0)
  41. {
  42. cout << "Error: Number of units must be greater than 0.\n";
  43. return 0;
  44. }
  45.  
  46. // Determine discount based on quantity
  47. if (units >= 100)
  48. discount = 0.50;
  49. else if (units >= 50)
  50. discount = 0.40;
  51. else if (units >= 20)
  52. discount = 0.30;
  53. else if (units >= 10)
  54. discount = 0.20;
  55.  
  56. // Calculate total cost
  57. totalCost = (units * PRICE) * (1.0 - discount);
  58.  
  59. // Display result
  60. cout << fixed << setprecision(2);
  61. cout << "Total cost: $" << totalCost << "\n";
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter the number of units sold: Total cost: $1621867.50