Heres the two codes together but am getting error again
main.c: In function ‘create_random_item’: main.c:84:69: warning: missing terminating " character 84 | char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", " | ^ main.c:84:69: error: missing terminating " character main.c:91:1: error: expected expression before ‘typedef’ 91 | typedef struct { | ^~~~~~~ main.c:263:1: error: expected declaration or statement at end of input 263 | } | ^
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
typedef struct {
char name[100];
char category;
char manufacturer[100];
char company[100];
float purchased_price;
float sale_price;
int quantity;
time_t purchased_date;
time_t production_date;
time_t expiry_date;
unsigned long barcode;
int store_code;
char currency[4];
} Item;
typedef struct {
time_t purchase_time;
Item *items;
int item_count;
} Receipt;
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';
}
unsigned long generate_barcode(Item *item) {
char encrypted_name[100], encrypted_company[100];
encrypt_caesar_cipher(item->name, 3, encrypted_name);
encrypt_caesar_cipher(item->company, 3, encrypted_company);
unsigned long barcode = 0;
for (int i = 0; encrypted_name[i] != '\0'; i++) {
barcode += encrypted_name[i];
}
for (int i = 0; encrypted_company[i] != '\0'; i++) {
barcode += encrypted_company[i];
}
return barcode;
}
Item create_random_item() {
Item item;
char *names[] = {"Apple", "Banana", "Orange", "Pear", "Grapes", "Pineapple", "Watermelon", "Strawberry", "Mango", "Kiwi"};
int name_index = rand() % 10;
strcpy(item.name, names[name_index]);
char categories[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'};
int category_index = rand() % 12;
item.category = categories[category_index];
char *manufacturers[] = {"Apple Inc.", "Samsung", "Microsoft", "Google", "Amazon", "Sony", "Nike", "Adidas", "Puma", "Reebok"};
int manufacturer_index = rand() % 10;
strcpy(item.manufacturer, manufacturers[manufacturer_index]);
strcpy(item.company, "ABC Company");
item.purchased_price = (float) (rand() % 100 + 1);
item.sale_price = item.purchased_price * (1.0 + ((float) (rand() % 20 + 1) / 100.0));
item.quantity = rand() % 10 + 1;
item.purchased_date = time(NULL);
item.production_date = item.purchased_date - (rand() % 60) * 24 * 60 * 60; // 0-60 days before purchase
item.expiry_date = item.production_date + (rand() % 180) * 24 * 60 * 60; // 0-180 days after production
item.store_code = rand() % 10000 + 1;
char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", "
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct {
char name[50];
char category;
char company[50];
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;
int category_random = rand() % 12;
// Assign random category
if (category_random <= 3) {
item.category = 'A';
} else if (category_random <= 7) {
item.category = 'B';
} else if (category_random <= 10) {
item.category = 'C';
} else {
item.category = 'D';
}
// Generate random values for item fields
char *names[4] = {"apple", "banana", "chocolate", "water bottle"};
strcpy(item.name, names[rand() % 4]);
strcpy(item.company, "ABC Company");
item.purchased_price = ((rand() % 100) + 1) / 10.0;
item.sale_price = item.purchased_price;
item.quantity = rand() % 10 + 1;
item.purchased_date = time(NULL);
item.production_date = item.purchased_date - (rand() % 60) * 24 * 60 * 60; // 0-60 days before purchase
item.expiry_date = item.production_date + (rand() % 180) * 24 * 60 * 60; // 0-180 days after production
item.store_code = rand() % 10000 + 1;
strcpy(item.currency, "USD");
item.barcode = generate_barcode(&item);
return item;
}
// Define function to create 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;
// Set a random currency
char *currencies[] = {"USD", "EUR", "GBP", "JPY", "CAD", "AUD", "CHF", "CNY"};
int currency_index = rand() % 8;
strcpy(item.currency, currencies[currency_index]);
// Set a random barcode
item.barcode = generate_barcode(&item);
return item;
}
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';
}
unsigned long generate_barcode(Item *item) {
// Encrypt the required fields
char encrypted_name[100], encrypted_company[100];
encrypt_caesar_cipher(item->name, 3, encrypted_name);
encrypt_caesar_cipher(item->company, 3, encrypted_company);
// Combine the encrypted information to generate a barcode (just as an example, not an actual barcode)
unsigned long barcode = 0;
for (int i = 0; encrypted_name[i] != '\0'; i++) {
barcode += encrypted_name[i];
}
for (int i = 0; encrypted_company[i] != '\0'; i++) {
barcode += encrypted_company[i];
}
return barcode;
}
void generate_receipt(Item* items, int num_items) {
Receipt receipt;
receipt.purchase_time = time(NULL);
receipt.items = items;
receipt.item_count = num_items;
print_receipt(&receipt);
}
int main() {
srand(time(NULL));
int num_items = 5;
Item items[num_items];
for (int i = 0; i < num_items; i++) {
items[i] = create_random_item();
apply_discounts(&items[i], time(NULL));
}
generate_receipt(items, num_items);
return 0;
}