Hi. Can you please make this code work?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
typedef struct {
char name[50];
char category;
char manufacturer[50]; // Change company to manufacturer
float purchased_price;
float sale_price;
int quantity;
time_t purchased_date;
time_t production_date;
time_t expiry_date;
int store_code;
char currency[4];
long barcode;
} Item;
typedef struct {
time_t purchase_time;
Item *items;
int item_count;
} Receipt;
// Caesar cipher encryption
void encrypt_caesar_cipher(char *input, int key, char *output) {
int i = 0;
while (input[i] != '\0') {
char c = input[i];
if (isalpha(c)) {
char base = isupper(c) ? 'A' : 'a';
output[i] = (c - base + key) % 26 + base;
} else {
output[i] = c;
}
i++;
}
output[i] = '\0';
}
// Caesar cipher decryption
void decrypt_caesar_cipher(char *input, int key, char *output) {
encrypt_caesar_cipher(input, 26 - key, output);
}
// Function to generate a random item
Item create_random_item() {
Item item;
// Set a random item name
char *names[] = {"Apple", "Banana", "Orange", "Pear", "Grapes", "Pineapple", "Watermelon", "Strawberry", "Mango", "Kiwi"};
int name_index = rand() % 10;
strcpy(item.name, names[name_index]);
// Set a random item category
char categories[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'};
int category_index = rand() % 12;
item.category = categories[category_index];
// Set a random item manufacturer
char *manufacturers[] = {"Apple Inc.", "Samsung", "Microsoft", "Google", "Amazon", "Sony", "Nike", "Adidas", "Puma", "Reebok"};
int manufacturer_index = rand() % 10;
strcpy(item.manufacturer, manufacturers[manufacturer_index]);
// Set a random purchased price
item.purchased_price = (float) (rand() % 100 + 1);
// Set a random sale price
item.sale_price = item.purchased_price * (1.0 + ((float) (rand() % 20 + 1) / 100.0));
// Set a random quantity
item.quantity = rand() % 10 + 1;
// Set a random purchased date
item.purchased_date = time(NULL) - (rand() % (30 * 24 * 60 * 60)); // up to 30 days ago
// Set a random production date
item.production_date = time(NULL) - (rand() % (365 * 24 * 60 * 60)); // up to 1 year ago
// Set a random expiry date (between 1 and 3 years from the production date)
item.expiry_date = item.production_date + ((rand() % 730) + 365) * 24 * 60 * 60;
// Set a random store code
item.store_code = rand() % 10000;
int main() {
int bought_items[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
float regular_price[12] = { 2.99, 4.99, 1.99, 3.49, 0.99, 1.49, 2.99, 3.99, 5.49, 4.49, 1.99, 2.49 };
int promotion[12] = { 20, 10, 30, 15, 0, 5, 10, 20, 25, 15, 0, 5 };
int returned_items[3] = { 5, 8, 11 };
int encrypt_method[12] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5 };
int i, j;
float sale_price, total_price = 0.0;
char barcode[7];
// 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, "UNK%d", bought_items[i]);
break;
}
// Calculate the sale price of the item based on the promotion percentage
sale_price = regular_price[i] * (1 - promotion[i] / 100.0);
// Check if the item is being returned
for (j = 0; j < 3; j++) {
if (bought_items[i] == returned_items[j]) {
sale_price = 0.0;
break;
}
}
// Print the barcode and the sale price of the item
printf("Item %d: %s - $%.2f\n", i+1, barcode, sale_price);
// Add the sale price to the total price
total_price += sale_price;
}
// Print the total price
printf("Total price: $%.2f\n", total_price);
return 0;
}