Internet Provider Switch Program Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster

Internet Provider Switch Program Help

 
0
  #1
21 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster
 
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)
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster
 
0
  #3
21 Days Ago
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. int main()
  8. {
  9. //declare constants and variables
  10. double packageA = $9.95;
  11. double packageB = $14.95;
  12. double packageC = $19.95;
  13. char pkg = ' ';
  14. int hrs = 0;
  15.  
  16. //get input items
  17. 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;
  18. 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;
  19. cout << "C. For $19.95/mo. unlimited access is provided." << endl;
  20. cout << "Enter A, B, or C: "'
  21. cin >> pkg;
  22. cout << "Enter the number of hours used: ";
  23. cin >> hrs;
  24.  
  25.  
  26.  
  27. //enter input data
  28. cout<<"Enter pkg: ";
  29. cin>>pkg;
  30. pkg = toupper(pkg);
  31.  
  32. if( pkg==A || pkg==B || pkg==C)
  33.  
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 302
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 33
jonsca jonsca is offline Offline
Posting Whiz
 
0
  #4
21 Days Ago
should be if(pkg == 'A' || pkg=='B' || pkg == 'C') otherwise they won't match character for character.

Your switch statement should look like:
  1. switch(pkg)
  2. {
  3. case 'A': //case A goes here
  4. break;
  5. case 'B' : // case B goes here
  6. break;
  7. etc.
  8. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster
 
0
  #5
21 Days Ago
I'm getting there, but still getting syntax errors.

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. //declare constants and variables
  8. const double packageA = 9.95;
  9. const double packageB = 14.95;
  10. const double packageC = 19.95;
  11. char pkg = ' ';
  12. int hrs = 0;
  13. double chg = 0.0;
  14.  
  15.  
  16. //get input items
  17. 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;
  18. 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;
  19. cout << "C. For $19.95/mo. unlimited access is provided." << endl;
  20. cout << "Enter A, B, or C: "'
  21. cin >> pkg;
  22. pkg = toupper(pkg);
  23.  
  24. if (pkg == 'A'|| pkg =='B' || pkg =='C')
  25.  
  26. //perform calculations
  27. cout<<"Enter hours: ";
  28. cin>>hrs;
  29.  
  30. if(hrs>=0 && hrs<=744)
  31. {
  32. {
  33. switch (pkg)
  34.  
  35. case 'A':
  36. chg = packageA + ( (hrs>10) ? (hrs-10)*2 : 0 );
  37.  
  38.  
  39. if (hrs<=10)
  40. chg= packageA;
  41. else if (hrs>11 && hrs <=50)
  42. chg= packageA+( (hrs>20 && hrs<=50) ? (hrs-20)*3 : 0 );
  43. else if (hrs>51)
  44. chg= packageA+((hrs-51)*4 : 0);
  45. case 'B':
  46. chg = packageB + ( (hrs >20)? (hrs-20)*1 : 0);
  47.  
  48. if (hrs <=20)
  49. chg = packageB;
  50. else if (hrs>21 && hrs <=75)
  51. chg - packageB + ( (hrs > 21) ? (hrs - 21) * 3 : 0 );
  52. else if (hrs > 75)
  53. chg = packageB + ((hrs - 75) * 4 : 0);
  54. //end ifs
  55. case 'C' :
  56. chg = packageC;
  57. }//end switch
  58.  
  59. //display number
  60. cout << "Your charges are: $" <<chg<<endl;
  61. return 0;
  62. } //end of main function
  63.  
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 302
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 33
jonsca jonsca is offline Offline
Posting Whiz
 
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. switch(variable) { //all the cases in here}
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster

Please help :)

 
0
  #7
16 Days Ago
I am still having problems with this program. I don't understand what I'm doing wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 302
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 33
jonsca jonsca is offline Offline
Posting Whiz
 
0
  #8
16 Days Ago
Post the portion that you are working on or refer us back to the old program as to where you are having problems
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 14
Reputation: vinochick is an unknown quantity at this point 
Solved Threads: 0
vinochick vinochick is offline Offline
Newbie Poster
 
0
  #9
16 Days Ago
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. //declare constants and variables
  8. const double packageA = 9.95;
  9. const double packageB = 14.95;
  10. const double packageC = 19.95;
  11. char pkg = ' ';
  12. int hrs = 0;
  13. double chg = 0.0;
  14.  
  15.  
  16. //get input items
  17. 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;
  18. 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;
  19. cout << "C. For $19.95/mo. unlimited access is provided." << endl;
  20. cout << "Enter A, B, or C: ";
  21. cin >> pkg;
  22. pkg = toupper(pkg);
  23.  
  24. if (pkg == 'A'|| pkg =='B' || pkg =='C')
  25.  
  26. //perform calculations
  27. cout<<"Enter hours: ";
  28. cin>>hrs;
  29.  
  30. if(hrs>=0 && hrs<=744)
  31. {
  32. {
  33. switch (pkg)
  34.  
  35. case 'A':
  36. chg = packageA + ( (hrs>10) ? (hrs-10)*2 : 0 );
  37.  
  38.  
  39. if (hrs<=10)
  40. chg= packageA;
  41. {
  42. else if (hrs>11 && hrs <=50)
  43. {chg= packageA+( (hrs>20 && hrs<=50) ? (hrs-20)*3 : 0 );}
  44. else if (hrs>51)
  45. {chg= packageA+((hrs > 51) ? (hrs-51)*4 : 0);
  46. }
  47. //end ifs
  48.  
  49. case 'B':
  50. chg = packageB + ( (hrs >20)? (hrs-20)*1 : 0);
  51.  
  52. if (hrs <=20)
  53. {chg = packageB;}
  54. else if (hrs>21 && hrs <=75)
  55. {chg - packageB + ( (hrs > 21) ? (hrs - 21) * 3 : 0 );}
  56. else if (hrs > 75)
  57. {chg = packageB + ((hrs - 75) * 4 : 0);}
  58. //end ifs
  59. case 'C' :
  60. chg = packageC;
  61. }//end switch
  62.  
  63. //display number
  64. cout << "Your charges are: $" <<chg<<endl;
  65. return 0;
  66. } //end of main function
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 302
Reputation: jonsca is an unknown quantity at this point 
Solved Threads: 33
jonsca jonsca is offline Offline
Posting Whiz
 
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, 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.
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC