R
Richard
Here is the program problem:
Month with 30 days have 720 hours, and month with 31 days have 744 hours.
February, with 28 days, has 672 hours. Enhance the input validation of the
program code below by asking user for the month (by name), and validating
that the number of hours entered is not more than the maximum number of the
entire month. There is a table that display how many days in each month and
their hours. It is unnecessary to for me to type them out. I new to C++
and I have problem assigning string value wheather with the " or ' symbol.
Please look at my variable declaration for the months and tell me what I did
wrong. Plus sugguest wheather i should use the switch or if statements
approve to 12 months. Note, I cannot use array function to solve this
problem. Here is the code.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int Hour;
double Charge;
char Choice ,Month[40];
char January[40]='January';
// ask for information
cout<<"This program calculate the monthly internet usage charge for a
customer. "<<endl<<endl;
cout<<"What Internet package have you purchased A,B or C? : ";
cin>>Choice;
while (!(Choice =='A' || Choice =='B'|| Choice == 'C'))
{
cout<<"You must enter package A B or C. Please try again!"<<endl;
return 0;
}
cout<<"What month do you need to calculate customer usage charge? :";
cin.getline(Month,40);
cin.ignore();
cout<<endl<<endl;
if (strcmp(Month,January)==0)
cout<<"The string";
/*switch(Month)
{
case "January": cout<<"Enter the hours usage for the month of "<<Month<<" !
:";
while (Hour > 744 && Hour < 0 )
{
cout<<"There are only 744 hours in the month of "<<Month<<endl;
cout<<"and you cannot enter hour usage less than 0."<<endl;
cout<<"please enter the correct hour! : ";
cin>>Hour;
cout<<endl<<endl;
}
}
*/
//cout<<"How many hours were used for the month of "<<Month" ? : ";
//cin>>Hour;
//if (Hour > 744 || Hour < 1)
//cout<<"You cannot have internet access longer than 744 hours or less than
1 hour."<<endl;
switch (Choice)
{
case 'A': if (Hour <=10)
{
Charge =9.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
if (Hour > 10)
{
Charge = 9.95 +((Hour-10)*2);
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
case 'B': if (Hour <=20)
{
Charge =14.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
if (Hour >= 20)
{
Charge = 14.95 +((Hour-20)*1);
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
case 'C': Charge = 19.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
}
Month with 30 days have 720 hours, and month with 31 days have 744 hours.
February, with 28 days, has 672 hours. Enhance the input validation of the
program code below by asking user for the month (by name), and validating
that the number of hours entered is not more than the maximum number of the
entire month. There is a table that display how many days in each month and
their hours. It is unnecessary to for me to type them out. I new to C++
and I have problem assigning string value wheather with the " or ' symbol.
Please look at my variable declaration for the months and tell me what I did
wrong. Plus sugguest wheather i should use the switch or if statements
approve to 12 months. Note, I cannot use array function to solve this
problem. Here is the code.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int Hour;
double Charge;
char Choice ,Month[40];
char January[40]='January';
// ask for information
cout<<"This program calculate the monthly internet usage charge for a
customer. "<<endl<<endl;
cout<<"What Internet package have you purchased A,B or C? : ";
cin>>Choice;
while (!(Choice =='A' || Choice =='B'|| Choice == 'C'))
{
cout<<"You must enter package A B or C. Please try again!"<<endl;
return 0;
}
cout<<"What month do you need to calculate customer usage charge? :";
cin.getline(Month,40);
cin.ignore();
cout<<endl<<endl;
if (strcmp(Month,January)==0)
cout<<"The string";
/*switch(Month)
{
case "January": cout<<"Enter the hours usage for the month of "<<Month<<" !
:";
while (Hour > 744 && Hour < 0 )
{
cout<<"There are only 744 hours in the month of "<<Month<<endl;
cout<<"and you cannot enter hour usage less than 0."<<endl;
cout<<"please enter the correct hour! : ";
cin>>Hour;
cout<<endl<<endl;
}
}
*/
//cout<<"How many hours were used for the month of "<<Month" ? : ";
//cin>>Hour;
//if (Hour > 744 || Hour < 1)
//cout<<"You cannot have internet access longer than 744 hours or less than
1 hour."<<endl;
switch (Choice)
{
case 'A': if (Hour <=10)
{
Charge =9.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
if (Hour > 10)
{
Charge = 9.95 +((Hour-10)*2);
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
case 'B': if (Hour <=20)
{
Charge =14.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
if (Hour >= 20)
{
Charge = 14.95 +((Hour-20)*1);
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
case 'C': Charge = 19.95;
cout<<"Your hours online is: "<<Hour<<endl;
cout<<"Your internet charge is: "<<Charge<<endl;
break;
}
}