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>
- using namespace std;
- int main() {
- double const PACKAGE_A = 4.99, PACKAGE_B = 9.99, PACKAGE_C = 19.99, A=.99, B=.59, C=.29, TAX=1.06;
- char userChoice;
- double downloads, totalDue, totalDueTaxed;
- system("color 8F");
- int i = 0;
- // have here code that you want NOT to repeat for ever
- 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) {
- 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? ";
- //system("pause");
- cin >> userChoice;
- switch (userChoice)
- {
- case 'a':
- case 'A':
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 10 * A + PACKAGE_A;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- break;
- case 'b':
- case 'B':
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 20 * B + PACKAGE_B;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- case 'c':
- case 'C':
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 30 * C + PACKAGE_C;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- default: cout << "cout << " ***Sorry we do not offer that package\n\n\t\t**************************************************************\t\t\n";
- }
- if (userChoice == 'a') {
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 10 * A + PACKAGE_A;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- system("pause");
- }
- if (userChoice == 'b') {
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 20 * B + PACKAGE_B;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- system("pause");
- }
- if (userChoice == 'c') {
- cout << "How many songs did you download this month? ";
- cin >> downloads;
- totalDue = downloads - 30 * C + PACKAGE_C;
- totalDueTaxed = totalDue * TAX;
- cout << "Your total bill for this month is $" << PACKAGE_A << " + $ " << .06*totalDue << " (for tax) = $" << totalDueTaxed << " \n";
- system("pause");
- }
- else
- {
- cout << " ***Sorry we do not offer that package\n\n\t\t**************************************************************\t\t\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement