lundi 27 novembre 2017

A market system

i have a task to do it's a market system. i was asked to write a program - stores the items and its price - reads the items that the customers want to buy and the number of each item - when the user enters zero then print the bill

and this is my code i make two structs one of them to the stored items and the another to the brought items then switch case to make the user to choose if he want to print the bill or continue then two for loops and if statement to compare between the items that had been bought and the items that in the market and print what he bought and the quantity and the price but it doesn't work. the compiler doesn't print the values that in the if statement. what is the wrong?

 #include <iostream>
    #include <conio.h>
    using namespace std;

    void main()
    {
        struct details
        {
            char name[20];
            int price;
        }item[50];
        //struct details item[50];
        struct bought
        {
            char name[20];
            int quantity;
        }boughtItem[50];
        //struct bought boughtItem[50];
        int n, i, q, v, m = 0, c = 0;
        cout << "Enter number of the stored items: \n";
        cin >> n;
        for (i = 0; i < n; i++)
        {
            cout << "Item name: \n";
            cin >> item[i].name;
            cout << "price: \n";
            cin >> item[i].price;
        }
        while (!m)
        {
            cout << "Press 0 to print the bill and 1 to continue\n";
            cin >> v;
            switch (v)
            {
            case 1:
                cout << "Item name: \n";
                cin >> boughtItem[c].name;
                cout << "The quantity: \n";
                cin >> boughtItem[c].quantity;
                c++;
                break;
            case 0:
                m=1;
                break;
            }
        }
        cout << "             *****  INVENTORY ***** \n";
        cout << "----------------------------------------------------------------- - \n";
        cout << "S.N.|    NAME           |  QUANTITY |  PRICE \n";
        cout << "----------------------------------------------------------------- - \n";
        for (i = 0; i < c; i++)
        {
            for (q = 0; q < n; q++)
            {
                if (boughtItem[i].name == item[q].name)
                {
                    cout << i + 1, boughtItem[i].name, boughtItem[i].quantity, item[q].price*boughtItem[i].quantity;
                }
            }
        }
        cout << "----------------------------------------------------------------- - \n";
        _getch();
    }

Aucun commentaire:

Enregistrer un commentaire