mardi 27 septembre 2022

create a shopping cart in c

Taking into account the following menu make a script that allows to read some option of the menu and read the number of portions of each food and calculate the total count. The program should ask if you want to add another food.

I need my program after selecting a product and quantity to show me my subtotal and ask me if I want to add more items, if the answer is yes, go back to the item menu and after selecting item and quantity give me again my subtotal of the 2 products, and if the answer is no, give me my total.

I don't know how to make it ask me if I want to add a product and go back to the menu to select a product and keep saving and incrementing the cart total.

#include <iostream>
#include <cstdlib>

using namespace std;

void Cabeza();
void Bistec();
void Lengua();
void Pastor();
void Refrescos();
void Total();

int main()
{
    int opcion;
    bool repetir = true;

    do
    {
        system("cls");

        cout << "\n\n\t\t\tTacos doña lupe" << endl;
        cout << "\t\t\t----------------" << endl;
        cout << "\n\t1. Tacos de Cabeza-----$8.0 c/u" << endl;
        cout << "\t2. Tacos de Bistec-----$8.5 c/u" << endl;
        cout << "\t3. Tacos de Lengua-----$10.0 c/u" << endl;
        cout << "\t4. Tacos al Pastor-----$7.5 c/u" << endl;
        cout << "\t5. Refrescos-----$14.0 c/u" << endl;
        cout << "\t0. SALIR" << endl;

        cout << "\n\tDe que los va a querer? ";
        cin >> opcion;

        int numero;
        float subtotal;
        switch (opcion)
        {
        case 1:
            Cabeza();
            break;

        case 2:
            Bistec();
            break;

        case 3:
            Lengua();
            break;

        case 4:
            Pastor();
            break;

        case 5:
            Refrescos();
            break;

        case 0:
            repetir = false;
            break;
        }
    } while (repetir);

    return 0;
}

void Cabeza()
{
    int numero;
    float subtotal;

    cout << "\n\tCuantos vas a querer? ";
    cin >> numero;

    subtotal = numero * 8;
    cout << "\tsubtotal: " << subtotal << endl;

    system("pause>nul");
}

void Bistec()
{
    int numero;
    float subtotal;

    cout << "\n\tCuantos vas a querer? ";
    cin >> numero;

    subtotal = numero * 8.5;
    cout << "\tsubtotal: " << subtotal << endl;

    system("pause>nul");
}

void Lengua()
{
    int numero;
    float subtotal;

    cout << "\n\tCuantos vas a querer?";
    cin >> numero;

    subtotal = numero * 10;
    cout << "\tsubtotal: " << subtotal << endl;

    system("pause>nul");
}

void Pastor()
{
    int numero;
    float subtotal;

    cout << "\n\tCuantos vas a querer? ";
    cin >> numero;

        subtotal = numero * 7.5;
        cout << "\tsubtotal: " << subtotal << endl;

    system("pause>nul");
}

void Refrescos()
{
    int numero;
    float subtotal;

    cout << "\n\tCuantos vas a querer?";
    cin >> numero;

    subtotal = numero * 14;
    cout << "\tsubtotal: " << subtotal << endl;

    system("pause>nul");
}

Aucun commentaire:

Enregistrer un commentaire