Thread: The 50 years old mom is back for help:

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    7

    Cool The 50 years old mom is back for help:

    The lab 3 assignment that I have is still having a problem on the computation. If anyone can help me again please on what I am missing or what is wrong why it won't compute:
    Here is what i have to do: And my code is below but don't work:
    First the code to do:
    computeCharges ( ... ):
    Should have no output to the screen and compute all rental / customer charges based on the following rules:
    1. New Release is charged at $2.99 per day
    2. Recent Release is charged at $3.99 for every period of 3 days or less
    3. Classic Release is charged at $2.99 for every period of 5 days or less
    4. Budget Release is charged at $1.00 for every period of 5 days or less
    Example: A recent release rented for 10 days (or 3 1/3 rental periods) would be charged at 4 x 3.99 (partial period is charged at the same rate as a full period).
    5. Customers with a coupon receive a $1.00 off on the total rental charge for a Recent or Classic rental. Coupon may be applied only to one video per customer and can not be applied to a lost video.
    6. An entry of zero in days rented will signify a lost video and the customer will be charged a $75.00 replacement fee.
    7. Any video returned after 90 days will be considered late (but not lost) and be charged at the lesser of the calculated fee (based on days rented) OR the replacement fee of $75.00.
    8. Sales Tax is to be computed at 8.6% on the total of all video rental charges.

    My code that won't work:
    //header
    void computecharges(double price, int DaysRented, char Category,char Y)
    {

    if (Category == 'N')
    price = DaysRented * 2.99;
    else if (Category =='R')
    {
    price = DaysRented * 3.99;
    if (Y == 'Y')
    price = price - 1;
    }
    else if (Category == 'C')
    {
    price = DaysRented * 2.99;
    if (Y == 'Y')
    price = price - 1;
    }
    else if (Category == 'B')
    price = DaysRented * 1.00;

    else if (DaysRented == 0)
    price = 75;

    else if (DaysRented == 90)

    price = 75;
    price = price + price * 0.086;
    }

    THEn THIS DISPLAY RECEIPT
    Store Name: Honest Abe's Bootleg Videos

    Customer Name:
    Address:
    City/State/Zip:

    Coupon Presented (Y/N):

    Days Coupon
    No. Video Title Category Rented Applied Late/Lost Charge
    === ============================== ========
    1.
    2.
    3.


    //header
    void displayreceipt(char Fullname[MAX_NAME + 1],char Address[MAX_NAME + 1],char City[MAX_NAME + 1],char Y, char VideoTitle[MAX_NAME + 1],char Category,int DaysRented,char CouponApplied[MAX_NAME + 1], char Late[MAX_NAME + 1], float Charge)
    {
    int i;
    system("cls");

    printf("Store Name: %s\n\n", TITLE);
    printf("Customer Name: %s", Fullname);
    printf(" Address: %s", Address);
    printf(" City/State/Zip: %s", City);
    printf("Coupon Presented (Y/N): %c", Y);

    printf(" Days Coupon \n");
    printf("No. Video Title Category Rented Applied Late/Lost Charge\n");
    printf("=== =================== ======== ====== ======= ========= ======\n");
    for (i = 0; i < MAX_VIDEO; i++)
    {
    printf("%i. %s %s %d %s %s %f\n", i + 1, VideoTitle, Category, DaysRented, Y, Late, Charge);
    }
    }

    When I try to display the receipt got an illegal operation:

    From the bottom of my heart to those who will help thanksagain

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    50 year old mom should learn to use code tags. Please use the following when posting code:

    [code]

    ... Type your code here ...

    [/code]

    If you wrap your code in those code tags, as per above, you'll get nicely readable code as per below:

    Code:
    #include <stdio.h>
    
    int main( void )
    {
        int x;
    
        for( x = 0; x < 10; x++ )
        {
            printf("Ooooh. Purdy.\n");
        }
    
        return 0;
    }
    This of course assumes you actually write nicely formatted code in the first place...

    Personally, unless it is an assignment requirement, I'd ditch the big cludgy "if/else" ladder, and use:

    Code:
    switch( Category )
    {
        case 'Y':
            ....do stuff here...
        break;
        case 'R':
            ...do stuff here...
        break;
        case (whatever):
            ...do stuff here...
        break;
        default:
            printf("Invalid choice.\n");
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    The error lies in your printf statement

    printf("%i. %s %s %d %s %s %f\n", i + 1, VideoTitle, Category, DaysRented, Y, Late, Charge);


    you use %s for Category,Y and Late, but those are only single chars. you should use %c

    An illegal operation usually means you are accessing memory that you should be. Most of the time it is attempting to use a NULL pointer, or a mix up like this with chars and strings.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A lot can happen in 50 years
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-04-2007, 04:44 AM
  2. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  3. the 50 years old mom is back and need help again
    By laraine andaya in forum C Programming
    Replies: 8
    Last Post: 08-11-2002, 03:00 PM
  4. The 50 years old is back for help
    By laraine andaya in forum C Programming
    Replies: 8
    Last Post: 08-01-2002, 09:11 AM
  5. Back to programming?
    By Korwin in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-23-2002, 06:51 AM