Sorry but I just dont unstand what your meaning as Iv change everything scanf to scanf_s. I use Microsoft laptop and so my compiler shows errors if I dont use scanf_s. Now I am confused but I just need this code to run effectivly. Thx.
#include <stdio.h>
#include <stdlib.h>
#include <string.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_s(barcode, "ABC%d", bought_items[i]);
break;
case 2:
sprintf_s(barcode, "DEF%d", bought_items[i]);
break;
case 3:
sprintf_s(barcode, "GHI%d", bought_items[i]);
break;
case 4:
sprintf_s(barcode, "JKL%d", bought_items[i]);
break;
case 5:
sprintf_s(barcode, "MNO%d", bought_items[i]);
break;
case 6:
sprintf_s(barcode, "PQR%d", bought_items[i]);
break;
case 7:
sprintf_s(barcode, "STU%d", bought_items[i]);
break;
default:
sprintf_s(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 was returned and adjust the total price accordingly
for (j = 0; j < 3; j++) {
if (returned_items[j] == bought_items[i]) {
total_price -= sale_price;
break;
}
}
// Add the sale price of the item to the total price
total_price += sale_price;
// Print the barcode and sale price of the item
printf("%s %.2f\n", barcode, sale_price);
}
// Print the total price of the items purchased
printf("Total: %.2f\n", total_price);
// Print the total price of the items bought
printf("Total price: $%.2f\n", total_price);
// Get user input for product information
char name[50];
char category;
char manufacturer[50];
float purchased_price;
sale_price;
int quantity;
char purchase_date[11];
char production_date[11];
char expiry_date[11];
int store_code;
char currency[4];
printf("\nEnter the name of the product: ");
scanf_s("%s", name);
printf("Enter the category: ");
scanf_s(" %c", &category);
printf("Enter the company/manufacturer name: ");
scanf_s("%s", manufacturer);
printf("Enter the purchased price: ");
scanf_s("%f", &purchased_price);
printf("Enter the sale price: ");
scanf_s("%f", &sale_price);
printf("Enter the quantity of purchased items: ");
scanf_s("%d", &quantity);
printf("Enter the date of purchase (yyyy-mm-dd): ");
scanf_s("%s", purchase_date);
printf("Enter the date of production (yyyy-mm-dd): ");
scanf_s("%s", production_date);
printf("Enter the expiry date (yyyy-mm-dd): ");
scanf_s("%s", expiry_date);
printf("Enter the store code: ");
scanf_s("%d", &store_code);
printf("Enter the currency of the country: ");
scanf_s("%s", currency);
// Encrypt the necessary fields to generate the barcode
// Print the barcode
printf("Barcode: %s\n", barcode);
// Determine the discount and print the tag color
float discount_percentage = (1.0 - (sale_price / purchased_price)) * 100.0;
if (discount_percentage > 20) {
printf("Tag color: Red\n");
}
else if (discount_percentage > 10) {
printf("Tag color: Yellow\n");
}
else {
printf("Tag color: Green\n");
}
return 0;
}
Sorry but I just dont unstand what your meaning as Iv change everything scanf to scanf_s. I use Microsoft laptop and so my compiler shows errors if I dont use scanf_s. Now I am confused but I just need this code to run effectivly. Thx.
#include <stdio.h>
#include <stdlib.h>
#include <string.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_s(barcode, "ABC%d", bought_items[i]);
break;
case 2:
sprintf_s(barcode, "DEF%d", bought_items[i]);
break;
case 3:
sprintf_s(barcode, "GHI%d", bought_items[i]);
break;
case 4:
sprintf_s(barcode, "JKL%d", bought_items[i]);
break;
case 5:
sprintf_s(barcode, "MNO%d", bought_items[i]);
break;
case 6:
sprintf_s(barcode, "PQR%d", bought_items[i]);
break;
case 7:
sprintf_s(barcode, "STU%d", bought_items[i]);
break;
default:
sprintf_s(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 was returned and adjust the total price accordingly
for (j = 0; j < 3; j++) {
if (returned_items[j] == bought_items[i]) {
total_price -= sale_price;
break;
}
}
// Add the sale price of the item to the total price
total_price += sale_price;
// Print the barcode and sale price of the item
printf("%s %.2f\n", barcode, sale_price);
}
// Print the total price of the items purchased
printf("Total: %.2f\n", total_price);
// Print the total price of the items bought
printf("Total price: $%.2f\n", total_price);
// Get user input for product information
char name[50];
char category;
char manufacturer[50];
float purchased_price;
sale_price;
int quantity;
char purchase_date[11];
char production_date[11];
char expiry_date[11];
int store_code;
char currency[4];
printf("\nEnter the name of the product: ");
scanf_s("%s", name);
printf("Enter the category: ");
scanf_s(" %c", &category);
printf("Enter the company/manufacturer name: ");
scanf_s("%s", manufacturer);
printf("Enter the purchased price: ");
scanf_s("%f", &purchased_price);
printf("Enter the sale price: ");
scanf_s("%f", &sale_price);
printf("Enter the quantity of purchased items: ");
scanf_s("%d", &quantity);
printf("Enter the date of purchase (yyyy-mm-dd): ");
scanf_s("%s", purchase_date);
printf("Enter the date of production (yyyy-mm-dd): ");
scanf_s("%s", production_date);
printf("Enter the expiry date (yyyy-mm-dd): ");
scanf_s("%s", expiry_date);
printf("Enter the store code: ");
scanf_s("%d", &store_code);
printf("Enter the currency of the country: ");
scanf_s("%s", currency);
// Encrypt the necessary fields to generate the barcode
// Print the barcode
printf("Barcode: %s\n", barcode);
// Determine the discount and print the tag color
float discount_percentage = (1.0 - (sale_price / purchased_price)) * 100.0;
if (discount_percentage > 20) {
printf("Tag color: Red\n");
}
else if (discount_percentage > 10) {
printf("Tag color: Yellow\n");
}
else {
printf("Tag color: Green\n");
}
return 0;
}