1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    Post C++ pseudocode and flow chart help

    Hi all, I have finished writing the code for the following program. I have concerns with the pseudocode that I have written and the flow chart seems really complicated. I dont know how to create it.

    Here is the question:

    An Internet service provider has three different subscription packages for its customers:
    Package A: For $9.95 per month 10 hours of access are provided. Additional hours are $2.00 per hour.
    Package B: For $14.95 per month 20 hours of access are provided. Additional hours are $1.00 per hour.
    Package C: For $19.95 per month unlimited access is provided.
    Write a program that calculates a customer s monthly bill. It should ask which package
    the customer has purchased and how many hours were used. It should then display the total amount due.
    Input Validation: Be sure the user only selects package A, B, or C. Also, the number of hours used in a month cannot exceed 744

    But if it helps then here is my program

    int main()
    char package;
    int hours;

    cout << "Select a package: \n" << endl;
    cout << "Package\t\tCost\t\tHours Provided\t\tExtra Hours" << endl;
    cout << "A\t\t$9.95\t\t10\t\t\t$2.00 per hour" << endl;
    cout << "B\t\t$14.95\t\t20\t\t\t$1.00 per hour" << endl;
    cout << "C\t\t$19.95\t\tUnlimited\t\tUnlimited" << endl;

    cout << "\nEnter the package purchased: ";
    cin >> package;
    while(package!= 'A' && package!='a' && package!='B' && package!='b'&&
    package!='C' && package!='c')
    {cout <<"\nError! You must select package A, B, or C. ";
    cout <<"Enter the package purchased: ";
    cin >> package;}

    cout <<"\nEnter the number of hours used: ";
    cin >>hours;
    while(hours < 0 || hours > 744)
    {cout <<"\nError! Hours cannot be negative or exceed 744. \n\nYou must enter appropriate hours.";
    cout <<"\n\nEnter the number of hours used. ";
    cin >> hours;}

    if(package == 'A' || package == 'a')
    {if (hours <= 10)
    cout<<"\nYour monthly fee is: $9.95";
    else cout<<"\nYour monthly fee is: $"<<9.95+(hours-10)*2;}

    if(package == 'B' || package == 'b')
    {if (hours <= 20)
    cout<<"\nYour monthly fee is: $14.95";
    else cout<<"\nYour monthly fee is: $"<<14.95 + hours - 20;}

    if(package == 'C' || package == 'c')
    cout<<"\nYour monthly fee is: $19.95";

    return 0;

    Thanks all.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    Please edit your post and put [code][/code] tags around your code.
    Copy again from your code editor so indentation is preserved.
    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
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    Please use code tags to preserve your code's formatting.

    Hitting the Reply button revealed that you didn't even indent your code in the first place. Indent your code properly and consistently! I strongly recommend using the Allman style (see http://en.wikipedia.org/wiki/Indent_style#Allman_style).

    Please break yourself of that nasty habit of hiding the braces ({}). Your goal should be to make your code readable, not indecipherable. Again, I strongly recommend that you use the Allman style (see http://en.wikipedia.org/wiki/Indent_style#Allman_style).

    You are asking us about your pseudo-code, so why do you neglect to post it? Of course since the flowchart is a graphic, then you would have difficulties posting that, but since pseudo-code is textual there should be no such problem.

    You are putting the cart before the horse. The purpose of pseudo-code and flowcharts is to develop the design of the program before you start coding it. If you had done this assignment properly, by the time you finished the code the pseudo-code and flowchart would have already been done. You don't normally create them after the fact.

    At any rate, you say that you already have pseudo-code but find it questionable, so why keep it secret?

IMN logo majestic logo threadwatch logo seochat tools logo