#include <stdio.h>
#include <string.h>

struct Menu {
    char code;
    char type[10];
    int price;
};

struct Order {
    char code;
    int quantity;
};

void main() {
    const struct Menu menu[] = {
        {'D', "Dada", 5000},
        {'P', "Paha", 4000},
        {'S', "Sayap", 3000},
    };    

    printf("\nDAFTAR HARGA\n");
    printf("Kode\tJenis\tHarga Per Potong\n");

    // looping untuk menunjukkan daftar menu
    for (int i = 0; i < 3; i++) {
        printf("%c\t%s\tRp. %d\n", menu[i].code, menu[i].type, menu[i].price);
    }

    printf("\nMasukkan Pesanan Anda\n");

    // signal untuk menampung jawaban user apakah mau pesan lagi atau tidak
    int menuLength = sizeof(menu) / 16;
    struct Order listOrder[menuLength];
    char signal = 'y';

    for (int i = 0; signal == 'y'; i++) {
        printf("\nPesanan ke - %d\n", i + 1);

        printf("Jenis [D/P/S]: ");
        scanf(" %c", &listOrder[i].code);

        printf("Jumlah: ");
        scanf("%int", &listOrder[i].quantity);

        // otomatis keluar jika jumlah order sama dengan jumlah menu
        if (i == 2)
            break;

        printf("Ada lagi (y/t) ? ");
        scanf(" %c", &signal);
    }

    int total = 0;

    printf("\nNota Belanja Anda:\n\n");
    printf("\t\tGEROBAK FRIED CHICKEN\n");
    printf("============================================================\n");
    printf("No\tJenis Potong\tHarga Satuan\tQty\tJumlah Harga\n");
    printf("============================================================\n");

    for (int i = 0; i < menuLength; i++) {
        struct Order currentOrder = listOrder[i];
        int price;
        char type[10];
        char isSet = 'y';

        for (int j = 0; j < menuLength; j++) {
            struct Menu currrentMenu = menu[j];

            if (currentOrder.code == currrentMenu.code) {
                price = currrentMenu.price;
                strcpy(type, currrentMenu.type);
                isSet = 'y';

                break;
            } else {
                isSet = 'n';
            }
        }

        if (isSet == 'n')
            continue;

        int totalPerItem = price * currentOrder.quantity;
        total += totalPerItem;

        printf("%d\t%s\t\tRp. %d\t%d\tRp. %d\n", i + 1, type, price, currentOrder.quantity, totalPerItem);
    }

    float tax = 0.1 * total;

    printf("============================================================\n");
    printf("\t\t\t\tJumlah bayar\tRp. %d\n", total);
    printf("\t\t\t\tPajak 10%%\tRp. %d\n", (int) tax);
    printf("\t\t\t\tTotal Bayar\tRp. %d\n", (int) tax + total);

    printf("\n\tTerima Kasih Atas Kunjungan Anda");
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: