Write a program that calculates a customer’s monthly bill. It should ask which package the customer has purchased and how many hours were used. It should then display the monthly charge, additional hours charge and total amount due.
Package A: For $ 9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
Package B: For $ 14.95 per month 20 hours of access are provided. Additional hours are $ 1.00 per hour.
Package C: For $ 19.95 per month unlimited access is provided.
# include <iostream>
# include <iomanip>
using namespace std;
int main()
{
double total = 0, charge = 0;//Stores total amount paid and initial charge
char choice ;//Stores input for package choice
double chargeA = 9.95;
double chargeB = 14.95;
double chargeC = 19.95;
int hours = 0;//Stores hours used
//Displays package choices to user
cout << "Package A: For $ 9.95 per month 10 hours of access are provided" << endl;
cout << "Additional hours are $2.00 per hour." << endl << endl;
cout << "Package B: For $ 14.95 per month 20 hours of access are provided."<< endl;
cout << "Additional hours are $ 1.00 per hour." << endl << endl;
cout << "Package C: For $ 19.95 per month unlimited access is provided." << endl << endl;
cout << "Please type in letter A, B, or C for your package choice." << endl << endl;
cin >> choice; //Stores user input for package choice
cout << "Now please enter how many hours was used." << endl << endl;
cin >> hours; //Stores user input for amount of hours used
//Calculates totals depending on which package user chose and hours entered
if (choice == 'A' || choice == 'a')
{
if (hours >=10)
total = ((hours - 10) * 2) + chargeA;
cout << "Your payment for this month is $" << setprecision(2) << fixed << total << endl << endl;
}
else if (choice == 'A' || choice == 'a')
{
if (hours <= 9 && hours >= 0)
total = chargeA;
cout << "Your payment for this month is $" << setprecision(2) << fixed << total << endl << endl;
}
return 0;
}
So far I have only worked on package A part but when I run the program, if I type any hours 10 or above the program works fine and runs the right commands, but once I get to the part where I entered an amount of hours less than 10, it just comes out to the answer 0 as if like it just skipped the whole line of code and did not run the line where it begins "else if".
When I changed it to that, now the first part of the code works where if I enter any number between 0 and 10 it works correctly, but if I enter any number greater than 10 it does not display the result.