Thread: I can't seem to get this cost of a moble service program to work.

  1. #1
    Registered User
    Join Date
    Jun 2013
    Posts
    7

    I can't seem to get this cost of a moble service program to work.

    [
    Code:
     1 #include<iostream>
     2 #include<cctype>
     3 usingnamespace std;
     4 
     5 int main()
     6 {
     7 char choice;
     8 double charges;
     9 double units;
    10 double package_A, package_B, package_C;
    11    
    12 do
    13       {
    14    cout <<"Which pakage are you shopping for?:Please enter A, B, C, or Q to quit."<< endl;
    15    cin>> choice;
    16    cout <<"How many message units?:"<< endl;
    17    cin>>units;
    18 while(unit <= 672);
    19    cout<<"Enter a number from 0 through 672 for message units."<<endl; 
    20           choice = toupper(choice);
    21    }while(choice !='A' && choice !='B' && choice !='C' && choice !='Q');
    22       (unit <= 672);
    23 switch(choice)
    24    {
    25 case'A':
    26       
    27       cout<<"How many massage units?:"<<endl;
    28       cin>>units;
    29       
    30 if (unit <=10)
    31       
    32       charges = 9.95
    33 else
    34       (unit > 10)
    35       
    36       charges = (unit * 2) + 9.95;
    37       cout<<"The charges are:"<< charges<< endl;
    38 break;
    39       
    40 case'B':
    41       
    42       cout<<"How many massage units?:"<<endl;
    43       cin>>units;
    44       
    45 if (unit <= 20)
    46       charges = 19.95;
    47       
    48 else (unit >20)
    49          charges = (unit - 20) + 19.95;
    50          cout<<"The charges are:"<< charges<< endl;
    51          
    52 break;
    53 case'C':
    54       
    55       cout<<"How many massage units?:"<<endl;
    56       cin>>units;
    57          
    58          charges = 39.95;
    59 break;
    60                
    61 case'Q':
    62       
    63          cout<<"How many massage units?:"<<endl;
    64          cin>>units;
    65          
    66          cout<<"Thank you for using this program. Goodbye."<< endl;
    67 break;
    68 default:
    69          cout<<"Enter only A, B, C, or Q."<<endl;
    70          }
    71          
    72 if (A < B && A > C)
    73    plan = (pakage_A - pakage_B);
    74     cout<<"By switching to Package A you would save:$"<< plan<<endl;
    75     
    76 elseif (pakage_B < pakage_C)
    77     
    78      cout<<"By switching to Package B you would save:$"<< plan<<endl;
    79     
    80 else
    81     cout<<"By switching to Package C you would save:$"<< plan<<endl;
    82 
    83 }
    84 
    85 return 0;
    86 
    87 }
    

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    For future reference, when you copy/paste code to the forum, choose the "paste as text option".

    30 if (unit <=10)
    31
    32 charges = 9.95
    33 else
    34 (unit > 10)
    35
    36 charges = (unit * 2) + 9.95;
    Two things,
    1. There is no condition associated with else, so get rid of the (unit > 10)
    2. Always use braces to make your intention explicit.
    Code:
     if (unit <=10) {
           charges = 9.95
     } else {
           charges = (unit * 2) + 9.95;
     }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help - Program to Compute Cost
    By abdool_raheem03 in forum C++ Programming
    Replies: 3
    Last Post: 08-13-2011, 08:18 PM
  2. running my program as service
    By daher in forum Windows Programming
    Replies: 5
    Last Post: 09-05-2008, 12:30 PM
  3. Changing a program into a Win Service
    By phal in forum Windows Programming
    Replies: 15
    Last Post: 08-03-2008, 05:31 PM
  4. program run as service
    By statquos in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2008, 11:43 AM
  5. Win32 Service doesn't work arghhh
    By cppnewbie81 in forum C++ Programming
    Replies: 7
    Last Post: 07-04-2007, 08:53 PM