Messages Problem

I can not seem to get the program to quit when Q is enter by the user and to display "Enter a number from 0 through 672 for message units" when a number from the ranges 0-672 are entered.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<cctype>
using namespace std;

int main()
{
	char package;
	double units;
	double fees_a, fees_b, fees_c;
	int A, B, C, Q;
	double pac_a,pac_b, pac_c;
	do
	{
	 do
		{
	cout <<"Which pakage are you shopping for?:Please enter A, B, C, or Q to quit."<< endl;
	cin>> package;
			 package = toupper(package);
	}while(package !='A' && package !='B' &&	package !='C' && package !='Q');
	
	cout<<"How many message units?:"<<endl;
	cin>>units;
	}while(units >= 0 || units <= 672);
					switch(package)
	{
		case 'A':
		
				
		if (units <=10)
		{
		fees_a = 9.95;
		cout<<"The charges are:"<< fees_a<< endl;
		}
	else
	{
				
		fees_a = (units - 10) * 2 + 9.95;
		cout<<"The charges are:"<< fees_a<< endl;
		break;
	}	
		case 'B':
		
			
      if (units <= 20)
		{
		fees_b = 19.95;
		cout<<"The charges are:"<< fees_b<< endl;
      }
	 else 
	 
	 {
			fees_b = ((units - 20) + 19.95);
			cout<<"The charges are:"<< fees_b<< endl;
		}	
			break;
			case 'C':
		        
			fees_c = 39.95;
			
			cout<<"The charges are:"<< fees_c<< endl;
		
			break;
					
		case 'Q':
								
			cout<<"Thank you for using this program. Goodbye."<< endl;
			break;
			default:
			cout<<"Enter only 0 through 672."<<endl;
	}
	if(fees_a < fees_b && fees_a < fees_c)
	{
		cout<<"Package A is a better plan"<< endl;
	}
	else if(fees_b < fees_c)
	{
		pac_b = (fees_a - units + 19.95) +20;
		pac_c = (fees_a - 39.95);
		
		cout<<"By switching to package B you would save:$"<<pac_b<<endl;
		cout<<"By switching to package C you would save:$"<<pac_c<<endl;
		
	}
	else
	{
		cout<<"Package C is a better plan"<<endl;			
			
	}	
					
		return 0;
		}
ok, i can see multiple problems, i'll start with the one you're asking about:
inside the case 'Q': block (start at line 64) ( you should call the exit() function, or at least order the main function to return before writing break;.

other problems:
in the case 'A': block (line 26), the if statement doesn't have a break inside it, while the else have one.
you can either put another break inside the if statement, or move the break that is inside the else to outside it, like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
case 'A':
		
				
	if (units <=10)
	{
		fees_a = 9.95;
	        cout<<"The charges are:"<< fees_a<< endl;
	}
	else
	{
		fees_a = (units - 10) * 2 + 9.95;
		cout<<"The charges are:"<< fees_a<< endl;
	}
        break;


the same problem exists in the case 'B': block, you should fix that too.
Topic archived. No new replies allowed.