I need some assistance

Write your question here.
Hi
I am new to programming and I am having some difficulty with my latest assignment.
An international phone company has 3 different subscription packages.

A 19.95 per month, 5 hours of talk time, .08 cents per minute overage
B 32.95 per month, 10 hours of talk time, .05 cents per minute of overage
C 45.95 per moth unlimited talk

Write a program that calculates a customers bill. It should prompt for which package (A,B, or C) the customer has.Only if the user indicates that they have package A or B should the program prompt for and get the number of minutes used.

If input is not valid an error message should be displayed and the user given a second chance to enter a value--package types can only be A,B, or C. minutes per month cannot be less than 0

any help would be appreciated I am completely stuck
Thanks
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  // Assignment 6, Internet/Phone access

#include <iostream>
#include <iomanip>

using namespace std;

int main()

{
	const double PACKAGE_A = 19.95;
	const double PACKAGE_B = 32.95;
	const double PACKAGE_C = 45.95;
	double minutes;
	double total;
	double overage;
	char package;

	cout << fixed << showpoint << setprecision(2);

	cout << "Please indicate which package was purchased by entering A, B, or C " << endl;
	cin >> package;
	
	if (package == 'A')
	{
		cout << "How many minutes were used?" << endl;
		cin >> minutes;
		{
			if (minutes > 300)
			{
				overage = (minutes - 300) * .08;
				total = overage + PACKAGE_A;
				cout << "Your toatal is $ " << total << endl;
			}
			else
				cout << "Your toatal is $ " << PACKAGE_A << endl;
		}
	}
	
			
		if (package == 'B')
			cout << "How many minutes were used?" << endl;
			cin >> minutes;
			{
				if (minutes > 600)
				{
					overage = (minutes - 600) * .05;
					total = overage + PACKAGE_B;
					cout << "Your toatal is $ " << total << endl;
				}
				else
				{
					cout << "Your toatal is $ " << PACKAGE_B << endl;
				}
			}
if ( package == 'C')
		{
		cout << "Your toatal is $ " << PACKAGE_C << endl;
		}
		else 
		cout << "Invalid Entry" << endl;
			
	return 0;
}

		 
Last edited on
closed account (48T7M4Gy)
Which part are you stuck on?
this was supposed to be the end but i forgot to copy it. I edited the code above

if ( package == 'C')
{
cout << "Your total is $ " << PACKAGE_C << endl;
}
else
cout << "Invalid Entry" << endl;

return 0;
}


I cant get option C to work and I can not figure out how to make it give a second chance for input

Last edited on
closed account (48T7M4Gy)
The switch case control structure is ideal for this but you can do it by using while alone to 'wrap' around the group of if tests with a while test, like this in pseudocode:

while( test for keepgoing true )
{
   input a,b or c

   if a etc etc

   if b etc etc

   if c etc etc

   input do you want to keepgoing

}

We just started the switch case stuff in the book and class but I am not that comfortable with yet. Now that I know it will work I will try it.

Thanks
closed account (48T7M4Gy)
Give it a go and get back if you have any problems. I wasn't exactly clear and just to make sure, you will still need the while loop, but the switch with 'default:' set up correctly will handle your if's cascade in a more efficient way. :)
I got it to work a lot better now. I just dont know how to give the user a second chance to enter a value.
This is what I have

// Assignment 6, Internet/Phone Access

#include <iostream>
#include <iomanip>

using namespace std;

int main()

{
double packageA = 19.95;
double packageB = 32.95;
double packageC = 45.95;
double minutes, total, overage;
char package;

cout << fixed << showpoint << setprecision(2);

cout << "Please indicate which package was purchased by entering A, B, or C: " << endl;
cin >> package;
switch (package)

{
case 'A': cout << "How many minutes were used? " << endl;
cin >> minutes;
overage = (minutes - 300) * .08;
total = overage + packageA;
cout << "Your total is $ " << total << endl;
break;

case 'B': cout << "How many minutes were used? " << endl;
cin >> minutes;
overage = (minutes - 600) * .05;
total = overage + packageB;
cout << "Your total is $ " << total << endl;
break;

case 'C': cout << "Your total is $ " << packageC << endl;
break;

default: cout << "You did not enter a valid choice " << endl;
}
return 0;
}
closed account (48T7M4Gy)
You need to refer back to my pseudo code. It's all there.
OK....Thanks again
Topic archived. No new replies allowed.