Minggu, 06 Agustus 2023

Program Warung Makan Sederhana bahasa C++


 

berikut kode programnya

#include <iostream>

#include <string>

#include <iomanip>


using namespace std;


// Function to calculate the total cost of the order

double calculateTotalCost(int quantity, double price) {

    return quantity * price;

}


int main() {

    // Menu items

    string menu[] = {"Nasi Goreng", "Mie Goreng", "Ayam Goreng", "Sate Ayam"};

    double prices[] = {15000.0, 12000.0, 18000.0, 20000.0};

    const int numMenuItems = sizeof(menu) / sizeof(menu[0]);


    cout << "Welcome to Warung Makan Sederhana!" << endl;

    cout << "Menu:" << endl;


    // Display the menu

    for (int i = 0; i < numMenuItems; i++) {

        cout << i + 1 << ". " << menu[i] << " - Rp " << prices[i] << endl;

    }


    // Take customer order

    int choice, quantity;

    double totalCost = 0.0;


    while (true) {

        cout << "Enter menu number (0 to finish order): ";

        cin >> choice;


        if (choice == 0) {

            break;

        } else if (choice >= 1 && choice <= numMenuItems) {

            cout << "Enter quantity: ";

            cin >> quantity;


            double itemTotal = calculateTotalCost(quantity, prices[choice - 1]);

            totalCost += itemTotal;


            cout << menu[choice - 1] << " (x" << quantity << ") added to the order. Subtotal: Rp " << itemTotal << endl;

        } else {

            cout << "Invalid menu number. Please try again." << endl;

        }

    }


    // Display the total bill

    cout << "===================" << endl;

    cout << "Total bill: Rp " << totalCost << endl;

    cout << "Thank you for dining with us!" << endl;


    return 0;

}


Tidak ada komentar:

Posting Komentar

Program Bank Sederhana Bahasa C++

  #include <iostream> #include <string> using namespace std; class BankAccount { private:     string accountNumber;     string a...