
please wait
cout << "How many hours were used?: ";
then delete one from the end.#include <ctype.h>
and :[code]toupper(userPackage);
after the user inputs userPackage. Then when testing the value of userPackage you only have to test the upper case so instead ofwhile (userPackage != 'A' && userPackage != 'a' && userPackage != 'b' && userPackage != 'B' && userPackage != 'c' && userPackage != 'C')
while (userPackage != 'A' && userPackage != 'B' && userPackage != 'C')
#include <iostream> #include <cctype> using namespace std; int main() { char userPackage; int hoursUsed; // Hours used by user int package_A_hours = 10; // Max hours for Package A int package_B_hours = 20; // Max hours for Package B int differenceHours; // Difference of hours allowed and hours used double additionalHours; // Cost of additional hours double amountDue_A; // Monthly bill of user for Package A double amountDue_B; // Monthly bill of user for Package B // Get package choice cout << "Please select one of the following Package choices:\n\n"; cout << "Package A: For $9.95/month 10 hours of access are provided. Additional hours are $2.00/hour.\n"; cout << "Package B: For $14.95/month 20 hours of access are provided. Additional hours are $1.00/hour.\n"; cout << "Package C: For $19.95 per UNLIMITED access is provided.\n\n"; cout << "Which package do you use? (A, B, C)\n"; cout << "Package: "; cin >> userPackage; userPackage = toupper(userPackage); while (userPackage != 'A' && userPackage != 'a' && userPackage != 'b' && userPackage != 'B' && userPackage != 'c' && userPackage != 'C') { cout << "Please enter a valid package choice: "; cin >> userPackage; userPackage = toupper(userPackage); } cout << "How many hours were used?: "; cin >> hoursUsed; // Validate hours used while (hoursUsed < 0 || hoursUsed > 744) { cout << "Please enter a valid amount of hours: "; cin >> hoursUsed; } switch( userPackage ) { case 'A': if (hoursUsed <= 10) cout << "Your monthly bill is $ 9.95\n"; else if (hoursUsed > 10) { differenceHours = hoursUsed - package_A_hours; additionalHours = differenceHours * 2.00; amountDue_A = additionalHours + 9.95; cout << "Your monthly bill is $" << amountDue_A << endl; } break; default: cout << "Você digitou uma userPackage invalida."; } |
while (userPackage != 'A' && userPackage != 'a' && userPackage != 'b' && userPackage != 'B' && userPackage != 'c' && userPackage != 'C')
while (userPackage != 'A' && userPackage != 'B' && userPackage != 'C')