Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This will simulate a music buying service with a price per song after a determined number of free songs
- // Switch Case Lab
- // Programmer: Noah Spahn
- // Last modified: 2/20/18 2:45pm
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main()
- {
- char packageChoice;
- double const
- PACKAGE_A_COST = 4.99,
- PACKAGE_B_COST = 9.99,
- PACKAGE_C_COST = 14.99,
- ADDITIONAL_SONG_A = .99,
- ADDITIONAL_SONG_B = .59,
- ADDITIONAL_SONG_C = .29,
- FREESONGS_A = 10,
- FREESONGS_B = 20,
- FREESONGS_C = 30,
- TAX = .06;
- double total, taxTotal, fSongs, package, eaSong, amountOfSongs, totalDueTaxed;
- system("color 8F");
- cout << "\n Switch Case GROUP Lab"
- << "\n Online music store\n"
- << " also needs nested if ... else statements\n"
- << " and the conditional operator\n"
- << " and use of \"continue\" in one place ONLY\n"
- << " by N. Spahn\n\n\n";
- while (true)
- {
- LOOP:
- 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? ";
- cin >> packageChoice;
- switch (packageChoice)
- {
- case 'a':
- case 'A':package = PACKAGE_A_COST, eaSong = ADDITIONAL_SONG_A, fSongs = FREESONGS_A;
- break;
- case 'b':
- case 'B':package = PACKAGE_B_COST, eaSong = ADDITIONAL_SONG_B, fSongs = FREESONGS_B;
- break;
- case 'c':
- case 'C':package = PACKAGE_C_COST, eaSong = ADDITIONAL_SONG_C, fSongs = FREESONGS_C;
- break;
- default: cout << "\t *** Sorry we do not offer that packet. \n" << endl << endl;
- system("pause");
- continue;
- }
- cout << "How many songs did you download this month? ";
- cin >> amountOfSongs;
- cin.ignore(100, '\n');
- if (abs(floor(amountOfSongs)) != amountOfSongs)
- {
- cout << "\n\t\t*** Your number of songs needs to be a whole number!\n";
- cout << "\n\t\t**************************************************************\t\t\n\n";
- goto LOOP;
- }
- if (amountOfSongs <= -1)
- {
- cout << "\n\n\t\t *** You can not have negative number of songs!\n\n";
- cout << "\n\t\t**************************************************************\t\t\n\n";
- goto LOOP;
- }
- if (amountOfSongs > fSongs) {
- total = (amountOfSongs - fSongs) * eaSong + package;
- taxTotal = TAX * total;
- totalDueTaxed = taxTotal + total;
- cout << "\nYour total bill for this month is $" << package << " + " << setprecision(3) << taxTotal << " (for tax) = $" << setprecision(4) << totalDueTaxed << " \n\n";
- cout << "\nYou have $ " << (amountOfSongs - fSongs)* eaSong << " extra charges for having " << amountOfSongs - fSongs << " more songs than your monthly limit of "<< fSongs << " free songs.\n";
- cout << "\n\t\t**************************************************************\t\t\n\n";
- }
- else {
- total = (amountOfSongs - fSongs) * eaSong + package;
- taxTotal = total * TAX;
- totalDueTaxed = taxTotal + total;
- cout << "\nYour total bill for this month is $" << package << " + " << taxTotal << " (for tax) = $" << totalDueTaxed << " \n\n";
- cout << "\n\t\t**************************************************************\t\t\n\n";
- }
- system("pause");
- goto LOOP;
- }
- }
- // Have Fun!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement