2
answers
0
watching
98
views

Hi. Was I supose to add the last code to the first? The output also show only this:

 

#include <stdio.h>

// Define the encryption methods for each item category int encrypt_method[] = {1, 2, 1, 3, 3, 5, 5, 5, 6, 7, 7, 4};

// Define the durable life period for each item category in days int life_period[] = {20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130};

// Define the sale promotion percentage for each item category int promotion[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

// Define the regular price for each item category float regular_price[] = {12.50, 10.20, 8.75, 6.99, 18.99, 15.55, 11.79, 9.99, 7.25, 5.49, 13.99, 23.99};

// Define the items bought by the customer int bought_items[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};

// Define the items returned by the customer int returned_items[] = {3, 7, 11};

int main() {
    char barcode[20]; 
    int i, j; 
    float price, sale_price, total_price = 0.0;

    // Generate barcodes for each item and print the receipt
    printf("Receipt:\n");

    for (i = 0; i < 12; i++) {
        // Encrypt the barcode using the appropriate encryption method
        switch (encrypt_method[i]) {
        case 1:
            sprintf(barcode, "ABC%d", bought_items[i]);
            break;
        case 2:
            sprintf(barcode, "DEF%d", bought_items[i]);
            break;
        case 3:
            sprintf(barcode, "GHI%d", bought_items[i]);
            break;
        case 4:
            sprintf(barcode, "JKL%d", bought_items[i]);
            break;
        case 5:
            sprintf(barcode, "MNO%d", bought_items[i]);
            break;
        case 6:
            sprintf(barcode, "PQR%d", bought_items[i]);
            break;
        case 7:
            sprintf(barcode, "STU%d", bought_items[i]);
            break;
        default:
            sprintf(barcode, "VWX%d", bought_items[i]);
            break;
        }

        // Calculate the price of the item, including any promotions
        price = regular_price[i];
        if (promotion[i] > 0) {
            sale_price = price * (1.0 - (float)promotion[i] / 100.0);
            price = sale_price;
        }

        // Check if the item was returned and adjust the total price accordingly
        for (j = 0; j < 3; j++) {
            if (returned_items[j] == bought_items[i]) {
                price = 0.0;
            }
        }

        // Print the item details and update the total price
        printf("%s - $%.2f\n", barcode, price);
        total_price += price;
    }

    // Print the total price of the items bought
    printf("Total price: $%.2f\n", total_price);

    return

For unlimited access to Homework Help, a Homework+ subscription is required.

Avatar image
Read by 2 people

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Avatar image
Read by 2 people
Already have an account? Log in

Related questions

Weekly leaderboard

Start filling in the gaps now
Log in