Program Flow

I can not seem to get this program to work. The logic may be my problem and the ranges between 0-672 will not work when the user enters a -number.
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
92
93
94
95
96
97
98
99
100
101
102
#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
		{
	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');
	
	do
	{
	
		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;
		break;
      }
	 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;
			
			return 0;
			
			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;
		}
		
		
						
I don't know what you are doing, but that's what you are declaring

1
2
3
4
5
  do
    {
      ...
    }
    while(units < 0 || units > 672);


that condition is true and keeps the do-while going only when units stores a value that is less than 0 or higher than 672.

basically your do-while executes at least 1 time no matter what is the value of units and then it checks that condition.
Topic archived. No new replies allowed.