You are using a version without Ads of this website. Please, consider donating:

### 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.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091`` ``````#include #include 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?:"<>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."<
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:
 ``1234567891011121314`` ``````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.