I hope this question makes sense. I am a beginner on C, and am attempting to make a food ordering system for university. I need to make it so with each order a receipt is generated from B001 to B0025, but so far the receipt number will not count up from B001 with any new orders. Any help would be greatly appreciated!!
My ideas was By converting r_num = 1 in to a string and then by using strcat to concatenate the newly made string to "B" which equalled B00, this would create the receipt number of B001. I then use strcpy to copy this string into the array orders[i] which is attached to my structure burger, and as i = 0 it would go into the first element of the array. Down the bottom of the code I attempted to use r_num +1 to then to make r_num = 2 so when the while loop returns to the start the process would begin again but once concatenated B002 would be created. Sorry if this makes no sense Im new at this
#include <stdio.h>
#include <string.h>
struct burger
{
char receipt_no[4];
int quantity;
float total_price;
};
int main()
{
struct burger orders[25];
char receipt[2], B[3] = "B00";
int option, price = 12, i=0, exit_switch = 0, r_num = 1;
float bill, percent;
while(exit_switch==0)
{
sprintf(receipt, "%d", r_num);
strcat(B, receipt);
strcpy(orders[i].receipt_no, B);
printf("Welcome to Tasty Burger\nPlace your order here...\n1. Order Burger\n2. Cancel\n3. Exit\n");
scanf("%d", &option);
switch (option)
{
case 1:
{
printf("How many burgers do you wish to order?\n");
scanf("%d", &orders[i].quantity);
if (orders[i].quantity >= 5){
bill = orders[i].quantity * price;
percent = bill / 10;
orders[i].total_price = bill - percent;
printf("Your total bill value is $%.2f\nDiscount of 10%% is $%.2f\nFinal bill value is $%.2f\n", bill, percent, orders[i].total_price);
printf("Your receipt number is %s\n", orders[i].receipt_no);
printf("Please go to a register and make the payment by quoting the Receipt Number – %s\n", orders[i].receipt_no);
}
else {
orders[i].total_price = orders[i].quantity * price;
printf("Your total bill value is $%.2f\n", orders[i].total_price);
printf("Your receipt number is %s\n", orders[i].receipt_no);
printf("Please go to a register and make the payment by quoting the Receipt Number – %s\n", orders[i].receipt_no);
}
}
}
r_num = r_num + 1;
i++;
}
return 0;
}