C++ program help (not entirely running) code error

Apr 14, 2013 at 12:22am
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 << "Select a package: " << endl;
cout << "Package\t\tCost\t\tHours Provided\t\tExtra Hours" << endl;
cout << "A\t\t$9.95\t\t10\t\t\t$2.00 per hour" << endl;
cout << "B\t\t$14.95\t\t20\t\t\t$1.00 per hour" << endl;
cout << "C\t\t$19.95\t\tUnlimited\t\tUnlimited" << endl;

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;
}

if (package == 'A' || package == 'a')
{if (hours <= 10)
total_amount = 9.95;
else
total_amount = 9.95+((hours-10)*2);
}
if(package == 'B' || package == 'b')
{if (hours <= 20)
total_amount = 14.95;
else
total_amount= 14.95+ ((hours-20)*1);
}
if(package == 'C' && package == 'c')
{total_amount=19.95;
}

system("pause");
return 0;
}
Apr 14, 2013 at 12:51am
What is the exact problem you have please, is there an error message or other symptom?
Apr 14, 2013 at 4:51pm
Nelson007, you were pretty close! It just needed a few cout statements and slight tweaking as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;

int main()
{
char package;
//double total_amount;   //Even skipped this!
int hours;

cout << "Select a package: \n" << endl;
cout << "Package\t\tCost\t\tHours Provided\t\tExtra Hours" << endl;
cout << "A\t\t$9.95\t\t10\t\t\t$2.00 per hour" << endl;
cout << "B\t\t$14.95\t\t20\t\t\t$1.00 per hour" << endl;
cout << "C\t\t$19.95\t\tUnlimited\t\tUnlimited" << endl;

cout << "\nEnter the package purchased: ";
cin >> package;
while(package!= 'A' && package!='a' && package!='B' && package!='b'&&
package!='C' && package!='c')
{cout <<"\nError! You must select package A, B, or C. ";
cout <<"Enter the package purchased: ";
cin >> package;}

cout <<"\nEnter the number of hours used: ";
cin >>hours;
cin.get();
while(hours < 0 || hours > 744)
{cout <<"\nError! Hours cannot be negative or exceed 744. \n\nYou must enter appropriate hours.";
cout <<"\n\nEnter the number of hours used. ";
cin >> hours;}

if(package == 'A' || package == 'a')
{if (hours <= 10)
cout<<"\nYour monthly fee is: $9.95";
else cout<<"\nYour monthly fee is: $"<<9.95+(hours-10)*2;}

if(package == 'B' || package == 'b')
{if (hours <= 20)
cout<<"\nYour monthly fee is: $14.95";
else cout<<"\nYour monthly fee is: $"<<14.95 + hours - 20;}

if(package == 'C' || package == 'c')
cout<<"\nYour monthly fee is: $19.95";

cin.get();
return 0;
}

Cheers, Don
Last edited on Apr 25, 2013 at 10:16am
Apr 14, 2013 at 7:29pm
@Donnie - Thank you soo much. You are a lifesaver. You program runs great. Also, would you have any idea how could i build a pseudocode for such a big program as this ? Can I copy and paste my pseudocode for your reference ? Also, how would I create a flowchart based on this program. That is a real biggie challenge. Any idea ? Thanks soo much again.
Apr 15, 2013 at 6:10am
Nelson007, really glad the program works. Sorry I can't help you with pseudocode or flowcharts , still have to learn about them. By all means post it, but might take me awhile to get my mind around it! Cheers, Don
Topic archived. No new replies allowed.