Thread: Getting an error message

  1. #1
    Unregistered
    Guest

    Cool Getting an error message

    Hi this is the 50 uears old mother again who go back to school and having problems with my assignment. Can you guys help me again? Everytime I select 4 to display the receipt, I got an error message that my program has illegal operation and will shut down. Where is my mistake.? I need to add the text below to compile completely:
    Should display all customer / rental input and computed information. The output should be nicely formatted and include a tabular summary of the costs. Any input codes should be displayed as the "string" value they represent (e.g. category code of N shuld display New and Y for coupon should display Yes). The output might look like the following: Days Coupon
    No. Video Title Category Rented Applied Late/Lost Charge
    === ============================== ========
    1. New 0 No Lost 75.00
    2. Recent 10 Yes 14.96
    3. Budget 91 No Late 19.00
    Subtotal: $108.96
    Tax (8.6%): $9.37
    Total Due: $118.33

    Here is my program:
    //header
    #include <stdio.h>
    #include <stdlib.h>

    #define MAX_NAME 30
    #define TITLE "Mabuhay Video Store"
    #define MAX_VIDEO 10

    void getcustomer(char Fullname[MAX_NAME + 1],char Address[MAX_NAME + 1],char City[MAX_NAME + 1],char Y);
    void getVideos(char Fullname[MAX_NAME + 1],char Y,char VideoTitle[MAX_NAME + 1],char Category, int DaysRented);
    void computecharges(double price, int DaysRented, char Category, char Y);
    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 main(void)
    {
    int choice;
    char Fullname[MAX_NAME + 1];
    char Address[MAX_NAME + 1];
    char City[MAX_NAME + 1];
    char Y = 'N';
    char VideoTitle[MAX_NAME + 1];
    char Category = 'R';
    int DaysRented = 0;
    double price = 0.0;
    char No ='N';
    char CouponApplied[MAX_NAME + 1];
    char Late[MAX_NAME + 1];
    float Charge = 0.0f;

    do
    {
    system ("cls");
    printf("=============================\n");
    printf(" %s\n", TITLE);
    printf("=============================\n\n");
    printf("1 Enter Customer Information\n");
    printf("2 Enter Rental Information\n");
    printf("3 Compute Charges\n");
    printf("4 Display Receipt\n");
    printf("5 Exit Program\n\n");
    printf(" Selection: ");
    scanf("%d",&choice);
    getchar();

    if(choice==1)
    {
    getcustomer(Fullname,Address,City,Y);
    }
    else if(choice==2)
    {
    getVideos(Fullname,Y, VideoTitle,Category, DaysRented);
    }
    else if(choice==3)
    {
    computecharges(price, DaysRented, Category, Y);
    }
    else if(choice==4)
    {
    displayreceipt(Fullname, Address, City, Y, VideoTitle, Category, DaysRented, CouponApplied, Late, Charge);
    }
    else
    {
    break;
    }
    }while(choice!=5);

    return EXIT_SUCCESS;
    }
    //header
    void getcustomer(char Fullname[MAX_NAME + 1],char Address[MAX_NAME + 1],char City[MAX_NAME + 1],char Y)
    {
    system("cls");

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

    }
    //header
    void getVideos(char Fullname[MAX_NAME + 1],char Y,char VideoTitle[MAX_NAME + 1],char Category, int DaysRented)
    {
    int i;

    system("cls");


    printf("Store Name: %s\n\n", TITLE);
    printf("Customer Name: %s\n", Fullname);
    printf("Coupon Presented: %c\n\n", Y);
    for (i = 0; i < MAX_VIDEO; i++)
    {
    printf("%i. VideoTitle: ", i + 1);
    gets(VideoTitle);
    printf("Category(N,R,C,B): ");
    scanf("%c",&Category);
    printf("DaysRented: ");
    scanf("%d", &DaysRented);
    getchar();
    }

    }
    //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;
    }

    //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);
    }
    }
    Please help:

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    >void getcustomer(char Fullname[MAX_NAME + 1],char Address[MAX_NAME + 1],char City[MAX_NAME + 1],char Y)

    Instead of specify the size of each char string you could just do this:
    Code:
    void getcustomer(char Fullname[],char Address[],char City[],char Y)
    The strings will automatically adjust to the size that is passed to the function.

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

    Use %c for char's. Here are all the rules for using printf:
    %c - int or wint_t When used with printf functions, specifies a single-byte character; when used with wprintf functions, specifies a wide character
    %d - int Signed decimal integer
    %I - int Signed decimal integer
    %o - int Signed octal integer
    %u - int Unsigned decimal integer
    %x - int Unsigned hexa, using "abcdef"
    %X - int Unsigned hexa using ABCDEF
    %e - double Signed value having the form [ ]d.dddd e [sign]ddd where d is a single decimal digit, dddd is one or more decimal digits, ddd is exactly three decimal digits, and sign is + or .
    %E - double Identical to the previous format, only that the exponent will be written E and not e.

    %f - double Signed value having the form [ ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.
    %g - double Signed value having the form [ ]dddd.dddd, where dddd is one or more decimal digits. The number of digits before the decimal point depends on the magnitude of the number, and the number of digits after the decimal point depends on the requested precision.
    %G - double The same as the previous one, only that the exponent will be written as E

    %n - Pointer to integer Number of characters successfully written so far to the stream or buffer; this value is stored in the integer whose address is given as the argument

    %p - Pointer to void Prints the address pointed to by the argument in the form xxxx:yyyy where xxxx is the segment and yyyy is the offset, and the digits x and y are uppercase hexadecimal digits.
    %s - String When used with printf functions, specifies a single-byte character string; when used with wprintf functions, specifies a wide-character string. Characters are printed up to the first null character or until the precision value is reached.
    %S - String When used with printf functions, specifies a wide-character string; when used with wprintf functions, specifies a single-bytecharacter string. Characters are printed up to the first null character or until the precision value is reached.
    Hope that helps.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

Popular pages Recent additions subscribe to a feed