ok how will i keep track of the items i bought? i have not the slightest clue on that. i dont even know where to start.
can someone point me in the right direction?

#include<iostream>
 using namespace std;
 int main()
 {
        char symb;
        int item_purch, numb_item_purch, quit,;
        double mug = 2.50f, teeshirt = 9.50f, pen= 0.75f,tot_mon = 30.0f;

        cout << "You have 30 dollars to spend.\n";
    do
        {
            cout << endl;
            cout << "What do you want to buy today?\n";


            cout << " A) Mugs $2.50 " << endl;
            cout << " B) teeshirt $9.50 " << endl;
            cout << " C) Pens .75 cents " << endl;
            cout << " D) Quit" << endl;
            cout << " Enter your letter and press Return when finished" << endl;
            cin >> symb;

            cout.setf(ios::fixed);
            cout.setf(ios::showpoint);
            cout.precision(2);


        switch (symb)
        {
            case 'A':;
            case 'a':;
            cout << " You have choosen A) mugs for $2.50 \n" << endl;
            tot_mon -= mug;
            cout << " You have " << tot_mon << " remaining \n" << endl;


            break;
            case 'B':;
            case 'b':;
            cout << " You have choosen B) teeshirt for $9.50 " << endl;
            tot_mon -= teeshirt;
            cout << " You have " << tot_mon << " remaining \n " << endl;

            break;

            case 'C':;
            case 'c':;
            cout << " You have choosen C) Pens for .75 cents " << endl;
            tot_mon -= pen;
            cout << " You have " << tot_mon << " remaining \n " << endl;

            break;

            case 'D':;
            case 'd':;
            cout << " You have choosen D) which means you want to Quit" << endl;
            tot_mon = 0;
            break;

            default:
            cout << "Input error. Select again" << endl;

        }

        if ( tot_mon == 0.0f )
                   cout << "You need more cash, you dont have enough\n" << endl;

        else

            cout << " Would you like anothe purchase, please choose another letter.\n" << endl;


        } while ( tot_mon >= 0.0f );
        {
            cout << "Thank you for shopping.\n";
        }
    return 0;
 }

Declare an int variable for each item you can purchase and initialize them all to zero. Do this at the start of the program. Then increase each variable within the appropriate case statement as an item is purchased.

int numb_item;

like so??

can i put it in a case like so, and keep the tally of items purchased ? i want a total for each of the 3 items

case 'C':
            case 'c':
            cout << " You have choosen C) Pens for .75 cents " << endl;
            (tot_mon -= pen) && (numb_item +=pen);
            cout << " You have " << tot_mon << " remaining \n " << endl;
            break;

            case 'D':
            case 'd':
            cout << " You have choosen D) which means you want to Quit" << endl;
            tot_mon = 0;
            break;

            default:
            cout << "Input error. Select again" << endl;
        }
        if ( tot_mon < 0.0f )
            cout << "You need more cash, you dont have enough\n" << endl;
        else
            cout << " Would you like anothe purchase, please choose another letter.\n" << endl;

        } while ( tot_mon >= 0.0f );

        cout << "Thank you for shopping.\n";

    cout << "You have spent" << tot_mon << "today\n";
    cin >> tot_mon;
    cout << "You have purchased << numb_item << "today" << endl;
    cin >> numb_item;

1) If you want to keep track of the total number of items sold then numb_items sounds like a reasonable variable name. numb_items should be declared and initialized to zero before this loop and it should be incremented by 1, not the cost of each item, each time a new item is purchased.

Separate post #3 line 4 into two separate statements:
(tot_mon -= pen) && (numb_item += pen);

becomes:

tot_mon -= pen; //implies total_mon is total money left to spend, not total money spent.
numb_item += pen;

but pen is the wrong increcment for numb_item. See above discussion.

2) Why should total_mon be assigned 0.0 if symb == 'D'? Use some other variable to stop the loop so I can keep my change if I only want to purchase 1 item with my 30 dollars. Using a different variable to trigger discontinuation of the loop will allow this to happen. Often a variable of type bool is used with the value initialized to true before the loop is started and the value changed to false within case 'D' (and maybe if there isn't enough money left to purchase any of the items offered for purchase, too, but that may not be part of your required functionality).

3) In addition, in one of your earlier posts you indicated the need to check to be sure there is enough money in the account to be able to pay for an item before you allow it to be purchased. If that protocol is still necessary it can be instituted once you have made the above modifications.

Edited 6 Years Ago by Lerner: n/a

This question has already been answered. Start a new discussion instead.