| | |
Internet Provider Switch Program Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2009
Posts: 14
Reputation:
Solved Threads: 0
I am very new to C++ and have the slightest idea where to start. Here are the directions for the project I'm doing. Below is a copy of the program that I have so far.
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 for 11-19 hours, $3.00 per hour for 20-50 hours and $4.00 per hour 51 or greater hours with maximum of 744 hours
Package B. For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour for 11-30 hours, $3.00 per hour for 31-75 hours and $4.00 per hour 76 or greater hours with maximum of 744 hours
Package C. For $19.95 per month unlimited access is provided.
Write a program that displays the menu above and use a switch case to calculate a customer’s monthly bill. The program will ask which package the customer has purchased and how many hours were used. It should then display the total amount due.
Input Validation: If user enters negative hours or enters a value other than A, B or C the program should display an error message and exit the program. If number of hours used in a month is greater than 744, display a message that the number hours used in a month cannot exceed 744.
#include <iostream>
using namespace std;
int main()
{
//declare constants and variables
double packageA = $9.95;
double packageB = $14.95;
double packageC = $19.95;
char pkg = ' ';
//enter input data
cout<<"Enter pkg: ";
cin>>pkg;
pkg = toupper(pkg);
if( pkg==A || pkg==B || pkg==C)
{
int hrs;
cout<<"Enter hours: ";
cin>>hrs;
if(hrs>=0 && hrs<=744)
{
int chg;
<strong class="highlight">switch</strong>(pkg)
{
case A:
chg = 9.95 + ( (hrs>10) ? (hrs-10)*2 : 0 );
break;
case:
{
if (hrs<=20)
chg= 14.95;
else if (hrs>20 && hrs <=50)
chg= 18+( (hrs>20 && hrs<=51) ? (hrs-20)*3 : 0 );
else if (hrs>51)
chg= 19.95;
break; }
case:
<strong class="highlight">3</strong>:
{
if (hrs<=200)
{
chg=25;
}
else if (hrs>200 && hrs<=450)
{
chg=35;
}
else if (hrs>450)
{
chg=50;
}
break;
}
default:
break;
}
cout<<"charges: "<<chg<<endl;
}
else
cout<<"Invalid hrs"<<endl;
}
else
{
cout<<"Invalid pkg"<<endl;
}
}//end main
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 for 11-19 hours, $3.00 per hour for 20-50 hours and $4.00 per hour 51 or greater hours with maximum of 744 hours
Package B. For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour for 11-30 hours, $3.00 per hour for 31-75 hours and $4.00 per hour 76 or greater hours with maximum of 744 hours
Package C. For $19.95 per month unlimited access is provided.
Write a program that displays the menu above and use a switch case to calculate a customer’s monthly bill. The program will ask which package the customer has purchased and how many hours were used. It should then display the total amount due.
Input Validation: If user enters negative hours or enters a value other than A, B or C the program should display an error message and exit the program. If number of hours used in a month is greater than 744, display a message that the number hours used in a month cannot exceed 744.
#include <iostream>
using namespace std;
int main()
{
//declare constants and variables
double packageA = $9.95;
double packageB = $14.95;
double packageC = $19.95;
char pkg = ' ';
//enter input data
cout<<"Enter pkg: ";
cin>>pkg;
pkg = toupper(pkg);
if( pkg==A || pkg==B || pkg==C)
{
int hrs;
cout<<"Enter hours: ";
cin>>hrs;
if(hrs>=0 && hrs<=744)
{
int chg;
<strong class="highlight">switch</strong>(pkg)
{
case A:
chg = 9.95 + ( (hrs>10) ? (hrs-10)*2 : 0 );
break;
case:
{
if (hrs<=20)
chg= 14.95;
else if (hrs>20 && hrs <=50)
chg= 18+( (hrs>20 && hrs<=51) ? (hrs-20)*3 : 0 );
else if (hrs>51)
chg= 19.95;
break; }
case:
<strong class="highlight">3</strong>:
{
if (hrs<=200)
{
chg=25;
}
else if (hrs>200 && hrs<=450)
{
chg=35;
}
else if (hrs>450)
{
chg=50;
}
break;
}
default:
break;
}
cout<<"charges: "<<chg<<endl;
}
else
cout<<"Invalid hrs"<<endl;
}
else
{
cout<<"Invalid pkg"<<endl;
}
}//end main
•
•
Join Date: Nov 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#2 21 Days Ago
revised code so far...
#include <iostream>
using namespace std;
int main()
{
//declare constants and variables
double packageA = $9.95;
double packageB = $14.95;
double packageC = $19.95;
char pkg = ' ';
int hrs = 0;
//get input items
cout << "A. For $9.95/mo. 10 access hours are provided. Additional hours are $2.00/hr. for 11-19 hours, $3.00/hr for 20-50 hrs. and $4.00/hr. for 51 hrs. or greater up to a maximum of 744 hours." << endl;
cout << "B. For $14.95/mo. 20 access hours are provided. Additional hours are $1.00/hr. for 21-30 hours, $3.00/hr for 31-75 hrs. and $4.00/hr. for 76 hrs. or greater up to a maximum of 744 hours." << endl;
cout << "C. For $19.95/mo. unlimited access is provided." << endl;
cout << "Enter A, B, or C: "'
cin >> pkg;
cout << "Enter the number of hours used: ";
cin >> hrs;
//enter input data
cout<<"Enter pkg: ";
cin>>pkg;
pkg = toupper(pkg);
if( pkg==A || pkg==B || pkg==C)
#include <iostream>
using namespace std;
int main()
{
//declare constants and variables
double packageA = $9.95;
double packageB = $14.95;
double packageC = $19.95;
char pkg = ' ';
int hrs = 0;
//get input items
cout << "A. For $9.95/mo. 10 access hours are provided. Additional hours are $2.00/hr. for 11-19 hours, $3.00/hr for 20-50 hrs. and $4.00/hr. for 51 hrs. or greater up to a maximum of 744 hours." << endl;
cout << "B. For $14.95/mo. 20 access hours are provided. Additional hours are $1.00/hr. for 21-30 hours, $3.00/hr for 31-75 hrs. and $4.00/hr. for 76 hrs. or greater up to a maximum of 744 hours." << endl;
cout << "C. For $19.95/mo. unlimited access is provided." << endl;
cout << "Enter A, B, or C: "'
cin >> pkg;
cout << "Enter the number of hours used: ";
cin >> hrs;
//enter input data
cout<<"Enter pkg: ";
cin>>pkg;
pkg = toupper(pkg);
if( pkg==A || pkg==B || pkg==C)
•
•
Join Date: Nov 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#3 21 Days Ago
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { //declare constants and variables double packageA = $9.95; double packageB = $14.95; double packageC = $19.95; char pkg = ' '; int hrs = 0; //get input items cout << "A. For $9.95/mo. 10 access hours are provided. Additional hours are $2.00/hr. for 11-19 hours, $3.00/hr for 20-50 hrs. and $4.00/hr. for 51 hrs. or greater up to a maximum of 744 hours." << endl; cout << "B. For $14.95/mo. 20 access hours are provided. Additional hours are $1.00/hr. for 21-30 hours, $3.00/hr for 31-75 hrs. and $4.00/hr. for 76 hrs. or greater up to a maximum of 744 hours." << endl; cout << "C. For $19.95/mo. unlimited access is provided." << endl; cout << "Enter A, B, or C: "' cin >> pkg; cout << "Enter the number of hours used: "; cin >> hrs; //enter input data cout<<"Enter pkg: "; cin>>pkg; pkg = toupper(pkg); if( pkg==A || pkg==B || pkg==C)
•
•
Join Date: Sep 2009
Posts: 302
Reputation:
Solved Threads: 33
0
#4 21 Days Ago
should be
Your switch statement should look like:
if(pkg == 'A' || pkg=='B' || pkg == 'C') otherwise they won't match character for character. Your switch statement should look like:
C++ Syntax (Toggle Plain Text)
switch(pkg) { case 'A': //case A goes here break; case 'B' : // case B goes here break; etc. }
•
•
Join Date: Nov 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#5 21 Days Ago
I'm getting there, but still getting syntax errors.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { //declare constants and variables const double packageA = 9.95; const double packageB = 14.95; const double packageC = 19.95; char pkg = ' '; int hrs = 0; double chg = 0.0; //get input items cout << "A. For $9.95/mo. 10 access hours are provided. Additional hours are $2.00/hr. for 11-19 hours, $3.00/hr for 20-50 hrs. and $4.00/hr. for 51 hrs. or greater up to a maximum of 744 hours." << endl; cout << "B. For $14.95/mo. 20 access hours are provided. Additional hours are $1.00/hr. for 21-30 hours, $3.00/hr for 31-75 hrs. and $4.00/hr. for 76 hrs. or greater up to a maximum of 744 hours." << endl; cout << "C. For $19.95/mo. unlimited access is provided." << endl; cout << "Enter A, B, or C: "' cin >> pkg; pkg = toupper(pkg); if (pkg == 'A'|| pkg =='B' || pkg =='C') //perform calculations cout<<"Enter hours: "; cin>>hrs; if(hrs>=0 && hrs<=744) { { switch (pkg) case 'A': chg = packageA + ( (hrs>10) ? (hrs-10)*2 : 0 ); if (hrs<=10) chg= packageA; else if (hrs>11 && hrs <=50) chg= packageA+( (hrs>20 && hrs<=50) ? (hrs-20)*3 : 0 ); else if (hrs>51) chg= packageA+((hrs-51)*4 : 0); case 'B': chg = packageB + ( (hrs >20)? (hrs-20)*1 : 0); if (hrs <=20) chg = packageB; else if (hrs>21 && hrs <=75) chg - packageB + ( (hrs > 21) ? (hrs - 21) * 3 : 0 ); else if (hrs > 75) chg = packageB + ((hrs - 75) * 4 : 0); //end ifs case 'C' : chg = packageC; }//end switch //display number cout << "Your charges are: $" <<chg<<endl; return 0; } //end of main function
•
•
Join Date: Sep 2009
Posts: 302
Reputation:
Solved Threads: 33
0
#6 21 Days Ago
Start with the first error and go through them one by one. It's just a bunch of stray stuff that you left in during editing. Just go to the lines the complier is complaining about, you'll catch em.
And, you need braces {} around your entire switch block, encompassing all the cases.
And, you need braces {} around your entire switch block, encompassing all the cases.
switch(variable) { //all the cases in here} •
•
Join Date: Nov 2009
Posts: 14
Reputation:
Solved Threads: 0
0
#9 16 Days Ago
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { //declare constants and variables const double packageA = 9.95; const double packageB = 14.95; const double packageC = 19.95; char pkg = ' '; int hrs = 0; double chg = 0.0; //get input items cout << "A. For $9.95/mo. 10 access hours are provided. Additional hours are $2.00/hr. for 11-19 hours, $3.00/hr for 20-50 hrs. and $4.00/hr. for 51 hrs. or greater up to a maximum of 744 hours." << endl; cout << "B. For $14.95/mo. 20 access hours are provided. Additional hours are $1.00/hr. for 21-30 hours, $3.00/hr for 31-75 hrs. and $4.00/hr. for 76 hrs. or greater up to a maximum of 744 hours." << endl; cout << "C. For $19.95/mo. unlimited access is provided." << endl; cout << "Enter A, B, or C: "; cin >> pkg; pkg = toupper(pkg); if (pkg == 'A'|| pkg =='B' || pkg =='C') //perform calculations cout<<"Enter hours: "; cin>>hrs; if(hrs>=0 && hrs<=744) { { switch (pkg) case 'A': chg = packageA + ( (hrs>10) ? (hrs-10)*2 : 0 ); if (hrs<=10) chg= packageA; { else if (hrs>11 && hrs <=50) {chg= packageA+( (hrs>20 && hrs<=50) ? (hrs-20)*3 : 0 );} else if (hrs>51) {chg= packageA+((hrs > 51) ? (hrs-51)*4 : 0); } //end ifs case 'B': chg = packageB + ( (hrs >20)? (hrs-20)*1 : 0); if (hrs <=20) {chg = packageB;} else if (hrs>21 && hrs <=75) {chg - packageB + ( (hrs > 21) ? (hrs - 21) * 3 : 0 );} else if (hrs > 75) {chg = packageB + ((hrs - 75) * 4 : 0);} //end ifs case 'C' : chg = packageC; }//end switch //display number cout << "Your charges are: $" <<chg<<endl; return 0; } //end of main function
•
•
Join Date: Sep 2009
Posts: 302
Reputation:
Solved Threads: 33
0
#10 16 Days Ago
Your statements in line 57 doesn't make any sense. The ternary operator for if statements needs 3 things. So delete the :0 there . Unless you have been explicitly taught the way you have it, it makes the code difficult to read. I haven't broken down all of your if statements to see if they make sense in light of your spec but one thing I noticed is you have no condition for the user specifying > 744 minutes, the program just exits silently.
Also,
Also,
if (pkg == 'A'|| pkg =='B' || pkg =='C') is just hanging off in the air. You need to put in braces if you want to encompass everything underneath it. Last edited by jonsca; 16 Days Ago at 1:39 am.
![]() |
Similar Threads
- I don't know what my anti-virus program is. (Viruses, Spyware and other Nasties)
- 2 Routers & a switch LAN probs (Networking Hardware Configuration)
- creating an instant messenger program in java (Java)
- Linksys cable gateway and comcast refusing to take my mac # so I can get connectivity (Networking Hardware Configuration)
- Need help writing a switch program for class (C++)
- Network cable is un-plugged! No it isn't. (Networking Hardware Configuration)
- Internet Security Question (Viruses, Spyware and other Nasties)
- Internet connection problem (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: to calculate square and cube form given input using arrays..
- Next Thread: Matrix multiplication
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





