Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 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. #include <iomanip>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. char packageChoice;
  13. double const
  14. PACKAGE_A_COST = 4.99,
  15. PACKAGE_B_COST = 9.99,
  16. PACKAGE_C_COST = 14.99,
  17. ADDITIONAL_SONG_A = .99,
  18. ADDITIONAL_SONG_B = .59,
  19. ADDITIONAL_SONG_C = .29,
  20. FREESONGS_A = 10,
  21. FREESONGS_B = 20,
  22. FREESONGS_C = 30,
  23. TAX = .06;
  24. double total, taxTotal, fSongs, package, eaSong, amountOfSongs, totalDueTaxed;
  25. system("color 8F");
  26.  
  27. cout << "\n Switch Case GROUP Lab"
  28. << "\n Online music store\n"
  29. << " also needs nested if ... else statements\n"
  30. << " and the conditional operator\n"
  31. << " and use of \"continue\" in one place ONLY\n"
  32. << " by N. Spahn\n\n\n";
  33.  
  34.  
  35.  
  36. while (true)
  37. {
  38. LOOP:
  39. cout << "Here are the options for packages offered in our store:\n" << " Package A: Monthly fee $ " << PACKAGE_A_COST << ". " << FREESONGS_A << " free songs and " << ADDITIONAL_SONG_A << " per song after that." << "\n Package B: Monthly fee $ " << PACKAGE_B_COST << ". " << FREESONGS_B << " free songs and " << ADDITIONAL_SONG_B << " per song after that." << "\n Package C: Monthly fee $ " << PACKAGE_C_COST << ". " << FREESONGS_C << " free songs and " << ADDITIONAL_SONG_C << " per song after that." << "\n\nPlease select the package name that you have? ";
  40. cin >> packageChoice;
  41. switch (packageChoice)
  42. {
  43. case 'a':
  44. case 'A':package = PACKAGE_A_COST, eaSong = ADDITIONAL_SONG_A, fSongs = FREESONGS_A;
  45. break;
  46. case 'b':
  47. case 'B':package = PACKAGE_B_COST, eaSong = ADDITIONAL_SONG_B, fSongs = FREESONGS_B;
  48. break;
  49. case 'c':
  50. case 'C':package = PACKAGE_C_COST, eaSong = ADDITIONAL_SONG_C, fSongs = FREESONGS_C;
  51. break;
  52. default: cout << "\t *** Sorry we do not offer that packet. \n" << endl << endl;
  53. system("pause");
  54. continue;
  55.  
  56. }
  57. cout << "How many songs did you download this month? ";
  58. cin >> amountOfSongs;
  59. cin.ignore(100, '\n');
  60.  
  61. if (abs(floor(amountOfSongs)) != amountOfSongs)
  62. {
  63. cout << "\n\t\t*** Your number of songs needs to be a whole number!\n";
  64. cout << "\n\t\t**************************************************************\t\t\n\n";
  65. goto LOOP;
  66. }
  67. if (amountOfSongs <= -1)
  68. {
  69. cout << "\n\n\t\t *** You can not have negative number of songs!\n\n";
  70. cout << "\n\t\t**************************************************************\t\t\n\n";
  71. goto LOOP;
  72.  
  73. }
  74. if (amountOfSongs > fSongs) {
  75. total = (amountOfSongs - fSongs) * eaSong + package;
  76. taxTotal = TAX * total;
  77. totalDueTaxed = taxTotal + total;
  78.  
  79.  
  80. cout << "\nYour total bill for this month is $" << package << " + " << setprecision(3) << taxTotal << " (for tax) = $" << setprecision(4) << totalDueTaxed << " \n\n";
  81. cout << "\nYou have $ " << (amountOfSongs - fSongs)* eaSong << " extra charges for having " << amountOfSongs - fSongs << " more songs than your monthly limit of "<< fSongs << " free songs.\n";
  82. cout << "\n\t\t**************************************************************\t\t\n\n";
  83.  
  84. }
  85. else {
  86.  
  87. total = (amountOfSongs - fSongs) * eaSong + package;
  88. taxTotal = total * TAX;
  89. totalDueTaxed = taxTotal + total;
  90. cout << "\nYour total bill for this month is $" << package << " + " << taxTotal << " (for tax) = $" << totalDueTaxed << " \n\n";
  91. cout << "\n\t\t**************************************************************\t\t\n\n";
  92. }
  93. system("pause");
  94. goto LOOP;
  95. }
  96.  
  97. }
  98.  
  99. // Have Fun!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement