Switch Statement
Using the switch to direct program progress
// Project 03-01
// Name: Jams of the month
#include <iostream>
using namespace std;
int main() {
char package{};
int jams{};
const int packageAFee{8};
const int packageBFee{12};
const int packageCFee{15};
const int packageAJams{2};
const int packageBJams{4};
const int packageCJams{6};
int price{};
cout << "What package do you own? A, B, or C? ";
cin >> package;
cout << "How many jams, jellies, or preserves did you purchase this month? ";
cin >> jams;
switch (package) {
case 'a':
case 'A':
if (jams <= packageAJams) {
price = packageAFee;
break;
}
price = (packageAFee + ((jams - packageAJams)*5));
break;
case 'b':
case 'B':
if (jams <= packageBJams) {
price = packageBFee;
break;
}
price = (packageBFee + ((jams - packageBJams)*4));
break;
case 'c':
case 'C':
if (jams <= packageCJams) {
price = packageCFee;
break;
}
price = (packageCFee + ((jams - packageCJams)*3));
break;
default:
cout << "Invalid selection" << endl;
price = 0;
return 0;
break;
}
cout << "You owe $" << price << endl;
return 0;
}