hellow guys im not asking too much but i dont have any idea how to add an array in this and change the printf to function oriented if you all can give me some good examples on both array and function oriented with close to my ordering system i would really appreciate it thanks.
#include<stdio.h>
#include<conio.h>
void main()
{
int code;
float price;
float totalf;
float payment;
float change;
int qty;
float mul;
int exceed;
float sub;
float subt;
int can;
int qty1;
int cel;
int yn;
totalf = 0;
qty1 = 0;
printf("\n\n\n\n\n");
printf("Code Item Price");
printf("\n");
printf("\n 1 Burger 10.50");
printf("\n");
printf("\n 2 Footlong 36.75");
printf("\n");
printf("\n 3 Shawarma 62.80");
printf("\n");
printf("\n 4 Fries 25.60");
printf("\n");
printf("\n 5 Juice 10.00");
printf("\n");
printf("\n 6 Shake 15.00");
printf("\n");
printf("\n Press . to exit after you order or just want to exit");
do
{
printf("\n\n");
printf("\nEnter Code: ");
scanf("%i", &code);
printf("Quantity: ");
scanf("%i", &qty);
qty1 = qty1+qty;
if(qty1<= 20)
{
switch(code)
{
case 1:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Burger");
printf("\nPrice per Item: 10.50");
price = 10.50;
mul = qty * price;
totalf = totalf + mul;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 2:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Footlong");
printf("\nPrice per Item: 36.75");
price = 36.75;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 3:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Shawarma");
printf("\nPrice per Item: 62.80");
price = 62.80;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 4:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Fries");
printf("\nPrice per Item: 25.60");
price = 25.60;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 5:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Juice");
printf("\nPrice per Item: 10.00");
price = 10.00;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 6:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Shake");
printf("\nPrice per Item: 15.00");
price = 15.00;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
default:
printf("Invalid Input!");
}
}
else
{
switch(code)
{
case 1:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Burger");
printf("\nPrice per Item: 10.50");
price = 10.50;
mul = qty * price;
totalf = totalf + mul;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 2:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Footlong");
printf("\nPrice per Item: 36.75");
price = 36.75;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 3:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Shawarma");
printf("\nPrice per Item: 62.80");
price = 62.80;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 4:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Fries");
printf("\nPrice per Item: 25.60");
price = 25.60;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 5:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Juice");
printf("\nPrice per Item: 10.00");
price = 10.00;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
case 6:
printf("Current Item Order: ");
printf("%i", qty);
printf(" Shake");
printf("\nPrice per Item: 15.00");
price = 15.00;
mul = qty * price;
printf("\nCurrent Item price: ");
printf("%.2f", mul);
totalf = totalf + mul;
printf("\nCurrent Order Total: ");
printf("%.2f", totalf);
break;
default:
printf("Invalid Input!");
}
printf("\nExceeded Maximum Order");
}
}while(totalf < 1500.00 && qty1 < 20 );
if(totalf == 1500.00)
{
printf("\n\n");
printf("\nThis is the maximum amount to be ordered!");
}
if(qty1 == 20 || totalf == 1500.00)
{
printf("\n");
printf("\nThis will be your last order!");
}
if (totalf > 1500.00 || qty1 > 20)
{
printf("\n\n");
printf("\nYour Order Exceeded the Maximum Amount Allowed");
printf("\nPress 0 to cancel your order or Press 9 to deduct your order: ");
scanf("%i", &exceed);
switch(exceed)
{
case 9:
qty1;
do
{
printf("\nHow Much Amount will be cancelled? ");
printf("\nEnter Order Item Code to subtract: ");
scanf("%i", &cel);
switch(cel)
{
case 1:
price = 10.50;
printf("\nHow many burger to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
case 2:
price = 36.75;
printf("\nHow many footlong to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
case 3:
price = 62.80;
printf("\nHow many shawarma to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
case 4:
price = 25.60;
printf("\nHow many fries to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
case 5:
price = 10.00;
printf("\nHow many juice to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
case 6:
price = 15.00;
printf("\nHow many burger to remove: ");
scanf("%i", &qty);
sub = price * qty;
break;
}
subt = totalf - sub;
totalf = subt;
qty1 = qty1 - qty;
}while(totalf > 1500.00 || qty1 > 20);
break;
case 0:
can = 1;
break;
}
}
else
{
totalf;
}
if(can == 1)
{
printf("\nOrder Cancelled!");
}
else
{
printf("\n");
printf("\nYour Total Order is: ");
printf("%.2f", totalf);
do
{
printf("\n");
printf("\nCustomer's Money: ");
scanf("%f", &payment);
if(payment < totalf)
{
printf("\nSorry you don't have sufficient cash!");
printf("\nDo you want to cancel your order? Press 1 to pay or press 0 to cancel: ");
scanf("%i", &yn);
}
else
{
change = payment - totalf;
printf("\nYour Change is: ");
printf("%.2f", change);
printf("\n\n THANK YOU!");
}
}while(payment<totalf yn="=" mode="hold" />}
printf("\n Canceled Order!");
getch();
}