0% found this document useful (0 votes)
9 views4 pages

PES2UG23CS686

This C program allows users to register a restaurant, order food, view their cart, and checkout. Users can input their personal information, register menu items with prices, and manage their cart by adding or removing items. The program runs in a loop until the user decides to exit, processing payments and resetting the cart after checkout.

Uploaded by

blastersvidit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

PES2UG23CS686

This C program allows users to register a restaurant, order food, view their cart, and checkout. Users can input their personal information, register menu items with prices, and manage their cart by adding or removing items. The program runs in a loop until the user decides to exit, processing payments and resetting the cart after checkout.

Uploaded by

blastersvidit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <stdio.

h>

int main() {
char userName[50], userAddress[100], userMobile[15], restaurantName[50];
char menuItems[5][50];
float prices[5];
int cart[5] = {0};
int choice, quantity;
float total = 0;
int restaurantRegistered = 0;

printf("Enter your name: ");


scanf("%s", userName);
printf("Enter your address: ");
scanf(" %[^\n]", userAddress);
printf("Enter your mobile number: ");
scanf("%s", userMobile);

while(1) {
printf("\n1. Register Restaurant\n2. Order\n3. View Cart\n4. Checkout\n5.
Remove item from cart\n6. Exit\nEnter your choice: ");
scanf("%d", &choice);

switch(choice) {
case 1:
printf("Enter your restaurant name: ");
scanf("%s", restaurantName);

printf("Enter 5 menu items and their prices for %s:\n",


restaurantName);
for(int i = 0; i < 5; i++) {
printf("Enter name of item %d: ", i+1);
scanf("%s", menuItems[i]);
printf("Enter price of item %d: ", i+1);
scanf("%f", &prices[i]);
}
restaurantRegistered = 1;
break;
case 2:
if(!restaurantRegistered) {
printf("Please register your restaurant first.\n");
break;
}

printf("\nMenu:\n");
for(int i = 0; i < 5; i++) {
printf("%d. %s - %.2f\n", i+1, menuItems[i], prices[i]);
}
printf("\nEnter item number to add to cart: ");
scanf("%d", &choice);
printf("Enter quantity: ");
scanf("%d", &quantity);
cart[choice-1] += quantity;
break;
case 3:
printf("\nCart:\n");
for(int i = 0; i < 5; i++) {
if(cart[i] > 0) {
printf("%s x %d = %.2f\n", menuItems[i], cart[i],
prices[i]*cart[i]);
}
}
break;
case 4:
printf("\nCheckout:\n");
for(int i = 0; i < 5; i++) {
if(cart[i] > 0) {
printf("%s x %d = %.2f\n", menuItems[i], cart[i],
prices[i]*cart[i]);
total += prices[i]*cart[i];
}
}
printf("\nTotal: %.2f\n", total);
printf("Payment processed successfully!\n");
for(int i = 0; i < 5; i++) {
cart[i] = 0;
}
total = 0;
break;
case 5:
printf("\nEnter item number to remove from cart: ");
scanf("%d", &choice);
cart[choice-1] = 0;
break;
case 6:
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
return 0;
}

You might also like