Hi all, i have problem running this code that i built based on this C++ question and I am having trouble running. Please helppp
The question is as follows
An Internet service provider has three different subscription packages for its customers:
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.
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 total amount due.
Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744.
This is my code
#include <iostream>
using namespace std;
int main()
{
char package;
double total_amount=0;
int hours =0;
cout << "Enter the package purchased:";
cin >> package;
while(package!= 'A' && package!='a' && package!='B' && package!='b'&&
package!='C' && package!='c')
{
cout <<"Error! You must select package A, B, or C. ";
cout << "Enter the package purchased: ";
cin >> package;
}
cout << "Enter the number of hours used:";
cin>>hours;
while(hours < 0 || hours > 744)
{
cout << "Error! Hours cannot be negative or exceed 744. You must enter appopriate hours. ";
cout << "Enter the number of hours used. ";
cin >> hours;
}
I did some changes in your program to make it more readable and easy to understand. Also, there was a '&&' in the last conditions which should actually be an '||' .
bool Quit = false;
char option;
while (!Quit){
//get input for option var
//tolower function
switch (option){
case'a':
//call function
break;
case'b':
//call function
break;
case'q': //user wants to quit
Quit = true;
//could use exit function here
break;
default:
//deal with bad input
}
}
@writetonsharma - Thank You soo much. This program runs great !
Also, I see you have used package = tolower(package);
What is the tolower function. I believe it has something to do with the inclusion of both upper and lower cases ? However, when I run the program and enter an invalid input. Say for instance i run p, instead of upper case package A. it says "Error! You must select package A, B, or C. " which is right but if I enter an upper case A right after. It goes in a loop frenzy. But if i enter lower case a instead. it works fine and goes on with saying enter the number of hours. What should I do ? Any way to fix this ? Can u help me ? Thanks man :)
Look more carefully at what I was saying in my last post - it explains how to deal with your problems.
The tolower function converts a char to lower case, toupper does the opposite. They are handy because it saves one from having to test a variable twice. There are several versions of them - google to find out how they work, or just look in the reference section on this page - top left.