Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. // This will simulate a music buying service with a price per song after a determined number of free songs
  2. // Switch Case Lab
  3. //Programmer: Noah Spahn
  4. // Last modified: 2/20/18 2:45pm
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. int main() {
  10. double const PACKAGE_A = 4.99, PACKAGE_B = 9.99, PACKAGE_C = 19.99, A=.99, B=.59, C=.29, TAX=1.06;
  11. char userChoice;
  12. double downloads, totalDue, totalDueTaxed;
  13. system("color 8F");
  14. int i = 0;
  15. // have here code that you want NOT to repeat for ever
  16.  
  17. cout<<"\n Switch Case GROUP Lab"
  18. <<"\n Online music store\n"
  19. <<" also needs nested if ... else statements\n"
  20. <<" and the conditional operator\n"
  21. <<" and use of \"continue\" in one place ONLY\n"
  22. <<" by N. Spahn\n\n\n";
  23.  
  24. while (true) {
  25.  
  26. cout << "Here are the options for packages offered in our store:\n" << " Package A: Monthly fee $ " << PACKAGE_A << ". 10 free songs and .99 per song after that." << "\n Package B: Monthly fee $ " << PACKAGE_B << ". 20 free songs and .59 per song after that." << "\n Package C: Monthly fee $ " << PACKAGE_C << ". 30 free songs and .29 per song after that." << "\n\nPlease select the package name that you have? ";
  27. //system("pause");
  28. cin >> userChoice;
  29. switch (userChoice)
  30. {
  31. case 'a':
  32. case 'A':
  33. cout << "How many songs did you download this month? ";
  34. cin >> downloads;
  35. totalDue = downloads - 10 * A + PACKAGE_A;
  36. totalDueTaxed = totalDue * TAX;
  37. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  38. break;
  39. case 'b':
  40. case 'B':
  41. cout << "How many songs did you download this month? ";
  42. cin >> downloads;
  43. totalDue = downloads - 20 * B + PACKAGE_B;
  44. totalDueTaxed = totalDue * TAX;
  45. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  46. case 'c':
  47. case 'C':
  48. cout << "How many songs did you download this month? ";
  49. cin >> downloads;
  50. totalDue = downloads - 30 * C + PACKAGE_C;
  51. totalDueTaxed = totalDue * TAX;
  52. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  53.  
  54. default: cout << "cout << " ***Sorry we do not offer that package\n\n\t\t**************************************************************\t\t\n";
  55.  
  56.  
  57. }
  58.  
  59. if (userChoice == 'a') {
  60. cout << "How many songs did you download this month? ";
  61. cin >> downloads;
  62. totalDue = downloads - 10 * A + PACKAGE_A;
  63. totalDueTaxed = totalDue * TAX;
  64. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  65. system("pause");
  66. }
  67. if (userChoice == 'b') {
  68. cout << "How many songs did you download this month? ";
  69. cin >> downloads;
  70. totalDue = downloads - 20 * B + PACKAGE_B;
  71. totalDueTaxed = totalDue * TAX;
  72. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  73. system("pause");
  74. }
  75. if (userChoice == 'c') {
  76. cout << "How many songs did you download this month? ";
  77. cin >> downloads;
  78. totalDue = downloads - 30 * C + PACKAGE_C;
  79. totalDueTaxed = totalDue * TAX;
  80. cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
  81. system("pause");
  82. }
  83. else
  84. {
  85. cout << " ***Sorry we do not offer that package\n\n\t\t**************************************************************\t\t\n";
  86. }
  87.  
  88.  
  89. }
  90.  
  91.  
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement