please help me fix my coding for this assignment

This is a discussion on please help me fix my coding for this assignment within the C Programming forums, part of the General Programming Boards category; please help me coding my assignment. it does not work properly. ill first show the ASSIGNMENT QUESTION and then my ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    4

    Unhappy please help me fix my coding for this assignment

    please help me coding my assignment. it does not work properly. ill first show the ASSIGNMENT QUESTION and then my SUGGESTED SOLUTION ( which does not get the proper calculation).
    thank u

    Question:

    Cellular (wireless) phones have become an increasingly
    important part of our everyday life. Choosing a cellular
    phone and accompanying service plan can however be
    confusing for many customers (especially those who
    do not read the fine print!).

    For your first programming assignment this semester,
    you are to write a C program that helps customers choose
    between 3 (simplified) cellular phone service plans and
    calculates the cost for the first month as well as the
    projected average costs for subsequent months.
    (see below for the details about each service plan).

    One time only expenses:
    Initial cost of phone-------------> $ 49.95
    One time activation charge--------> $ 35.00

    Service charges common to ALL plans:
    System access fee-----------------> $ 6.95 per month
    911 emergency fee-----------------> $ 0.25 per month

    Plan 1:
    Cost per month---> $25.00
    Included anytime minutes per month---> 150
    Special offers---> unlimited weekend calling
    additional per minute rate---> $0.25

    Plan 2:
    Cost per month---> $35.00
    Included anytime minutes per month---> 100
    Special offers---> unlimited evening & weekend calling
    additional per minute rate---> $0.20

    Plan 3:
    Cost per month---> $50.00
    Included anytime minutes per month---> 350
    Special offers---> none
    additional per minute rate---> $0.15

    Your program should begin by asking the user for three
    pieces of data:
    1. Estimated total number of minutes used per month.
    2. Percentage (5%, 10%, 25% etc.) of total minutes
    called in the weekday daytime (8 a.m. to 6 p.m.) hours.
    3. Percentage of total minutes called in the weekday
    evening (6 p.m. to 8 a.m.) hours.

    The percentage of total weekend minutes called may
    be calculated by subtracting (daytime + evening)
    from 100.

    Your program should then process the information,
    perform the necessary calculations, and display for
    the user which plan is the most cost effective for
    their particular usage levels, as well as display
    the first month's invoice and subsequent projected
    future month's invoice (1 only).

    NOTE: When determining the monthly invoice, the
    costs must also include taxes: GST(7%), & PST(8%).
    You may assume that billing is done on a per second
    basis (i.e. do not worry about rounding)
    You may also assume that only correct data
    (positive numeric) will be entered and that the
    percentages will always total to 100%.
    No data validation will be required.

    A few sample runs of the program should look like this:
    $ a.out
    ***Welcome to the Cellular Phone Analyzer (CPA)!***
    Enter the estimated total number of monthly minutes: 175
    Enter the percentage of daytime minutes: 80
    Enter the percentage of evening minutes: 10

    You should sign up for PLAN 1...
    First month's invoice------> $136.88
    Projected monthly invoice--> $ 39.19

    $ a.out
    ***Welcome to the Cellular Phone Analyzer (CPA)!***
    Enter the estimated total number of monthly minutes: 250
    Enter the percentage of daytime minutes: 10
    Enter the percentage of evening minutes: 50

    You should sign up for PLAN 1...
    First month's invoice------> $134.72
    Projected monthly invoice--> $ 37.03

    $ a.out
    ***Welcome to the Cellular Phone Analyzer (CPA)!***
    Enter the estimated total number of monthly minutes: 280
    Enter the percentage of daytime minutes: 90
    Enter the percentage of evening minutes: 5

    You should sign up for PLAN 3...
    First month's invoice------> $163.47
    Projected monthly invoice--> $ 65.78

    $ a.out
    ***Welcome to the Cellular Phone Analyzer (CPA)!***
    Enter the estimated total number of monthly minutes: 280
    Enter the percentage of daytime minutes: 10
    Enter the percentage of evening minutes: 80

    You should sign up for PLAN 2...
    First month's invoice------> $146.22
    Projected monthly invoice--> $ 48.53

    _________________________________

    MY CODE


    #include<stdio.h>

    main()
    {
    int monthly_minutes;

    int percent_daytime;

    int percent_evening;

    int percent_weekend;


    double GST_PST_Multiplier=1.15; /*for the value after tax */

    double initial_cost=49.95;

    double activation_charge=35.00;

    double sys_access_fee=6.95;

    double emergency_fee=0.25;

    double monthly_cost;

    double month_total;

    double first_invoice;

    double pmi; /* Projected Monthly Incone */

    double additional_minutes;

    double additional_charge;


    printf("***Welcome to the Cellular Phone Analyzer (CPA)!***\n");
    printf("Enter the estimated total number of monthly minutes:");
    scanf(" %d" , & monthly_minutes);
    printf("Enter the percentage of daytime minutes:");
    scanf(" %d" , & percent_daytime);
    printf("Enter the percentage of evening minutes:");
    scanf(" %d" , & percent_evening);
    percent_weekend = 100 - ( percent_daytime + percent_evening);;

    if(monthly_minutes<= 150 )
    {printf("You should sign up for PLAN 1\n");
    monthly_cost= 25.00;
    monthly_minutes=(percent_daytime/100 * monthly_minutes)+(percent_evening/100 * monthly_minutes);
    month_total=initial_cost+ activation_charge+ sys_access_fee+ emergency_fee + monthly_cost;
    first_invoice=month_total* GST_PST_Multiplier;
    printf("First month's invoice------>$ %.2lf\n",first_invoice);
    pmi=(sys_access_fee+ emergency_fee + monthly_cost) * GST_PST_Multiplier;
    printf("Projected monthly invoice-->$ %.2lf\n",pmi);

    }



    else if ( monthly_minutes >150 && percent_daytime < percent_evening && percent_weekend )
    {printf("You should sign up for PLAN 2\n");
    monthly_cost=35.00;
    monthly_minutes=percent_daytime/100 * monthly_minutes;
    if(monthly_minutes> 100)
    additional_minutes=monthly_minutes -100;
    else additional_minutes=0;
    additional_charge= 0.20 * additional_minutes;
    month_total=initial_cost+ activation_charge+ sys_access_fee+ emergency_fee + monthly_cost+additional_charge;
    first_invoice=month_total* GST_PST_Multiplier;
    printf("First month's invoice------>$ %.2lf\n",first_invoice);
    pmi=(sys_access_fee+ emergency_fee + monthly_cost+additional_charge) * GST_PST_Multiplier;
    printf("Projected monthly invoice-->$ %.2lf\n",pmi);



    }
    else if(monthly_minutes > 150 && monthly_minutes < 250)
    {
    printf("You should sign up for PLAN 1\n");
    monthly_cost=25.00;
    monthly_minutes=monthly_minutes -( (percent_weekend/100)* monthly_minutes);
    printf("%.2lf",percent_weekend);
    additional_minutes=monthly_minutes -150;
    additional_charge= 0.25 * additional_minutes;
    month_total=initial_cost+ activation_charge+ sys_access_fee+ emergency_fee + monthly_cost+additional_charge;
    first_invoice=month_total* GST_PST_Multiplier;
    printf("First month's invoice------>$ %.2lf\n",first_invoice);
    pmi=(sys_access_fee+ emergency_fee + monthly_cost+additional_charge) * GST_PST_Multiplier;
    printf("Projected monthly invoice-->$ %.2lf\n",pmi);

    }

    else if(monthly_minutes >= 250)
    {printf(" You should sign up for PLAN 3\n");
    monthly_cost=50.00;
    if (monthly_minutes >350)
    additional_minutes=monthly_minutes -350;
    else if (monthly_minutes <=350 && monthly_minutes > 275)
    additional_minutes=0;
    additional_charge= 0.15 * additional_minutes;
    month_total=initial_cost+ activation_charge+ sys_access_fee+ emergency_fee + monthly_cost+additional_charge;
    first_invoice=month_total* GST_PST_Multiplier;
    printf("First month's invoice------>$ %.2lf\n",first_invoice);
    pmi=(sys_access_fee+ emergency_fee + monthly_cost+additional_charge) * GST_PST_Multiplier;
    printf("Projected monthly invoice-->$ %.2lf\n",pmi);

    }
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One problem is you need to cast an int to a double before dividing:

    monthly_minutes=((double) percent_daytime/100 * monthly_minutes)+(percent_evening/100 * monthly_minutes);

    monthly_minutes=(double) percent_daytime/100 * monthly_minutes;

    monthly_minutes=monthly_minutes -( ((double) percent_weekend/100)* monthly_minutes);

    Another problem is figuring out which plan is cheapest. I think to do this correctly, you will have to calculate the cost for each plan, then choose the one which is lowest in price. This would requre changing your code so that it calculates the price for each plan first, then does a comparison to see which is cheapest.
    Last edited by swoopy; 01-29-2002 at 01:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. 3x syntax errors :S, Help a student finalise an assignment
    By Chickenhawk in forum C Programming
    Replies: 14
    Last Post: 07-27-2006, 05:14 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Replies: 1
    Last Post: 05-26-2006, 08:13 AM
  5. Hard programming assignment
    By Seiro in forum C Programming
    Replies: 3
    Last Post: 04-13-2006, 07:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21