Did i use the code tag correctly ? let me know?

Im trying to figure out how to error trap this program so if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly.

also i want to subtract the money they spend and tell them their remaining amount, also i want to keep track of the number of items they purchase.

when i do it all that comes up is a whole bunch of numbers.
can anyone help when you compile this program i want this format but the numbers arent right

can anyone help?

/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/

#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;

cout << "What do you want to buy today?\n";
cout << "You have 30 dollars to spend.\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;


switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n";
mug = 2.50;
cout << " You have " << curr_cash << " remaining \n ";
tot_mon = 30;
curr_cash = tot_mon - mug;
cout << " You have purchased " << numb_item_purch << " today \n ";
numb_item_purch = item_purch + 1;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 ";
teeshirt = 9.50;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents ";
pen = .75;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
}



cin >> tot_mon;
curr_cash = tot_mon - mon_spent;
cin >> curr_cash;
cin >> mon_spent;




return 0;
}

Better. But not quite. Put the tags around the CODE only. Not the entire message.

At least a step in the right direction.

Now you need to format your code. Indenting is required for people to follow it.

1) if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly.

Add another section in the switch statement after the case 'D': that looks something like this:

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

Whenever you want to do something over and over again you should be thinking about enclosing the recurring code in a loop. In this program you will probably end up with several loops bt the first one you should create has to do with repeating code a valid user selection from the menu has been achieved. I would flip these two lines:

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

and put the line with the question inside a loop with the menu and the switch statement. The loop would be controlled by a flag variable of type bool called something like invalidInput which is set to true before the start of the loop and set to false for all cases of input but the default case.

When you get that loop up and running then you can worry about keeping track of the money available.

so i got the remaining balance but i cant figure out how to keep track of the items purchased?

switch (symb)
        {
            case 'A':;
            case 'a':;
            cout << " You have choosen A) mugs for $2.50 \n";
            mug = 2.50;
            curr_cash = tot_mon - mug;
            cout << " You have " << curr_cash << " remaining \n ";
            tot_mon = 30;
            cout << " You have purchased " << numb_item_purch << " today \n ";
           numb_item_purch = item_purch+;
            cin >> numb_item_purch;

If you go to 3 stores, and you buy a mug at the first store, 2 mugs at the 2nd store, and 1 mug at the 3rd store, when you get home how can you tell how many mugs you bought? How can your program simulate that?

i would intialize the values 1st,
make a switch statement and in that switch statement i will have a counting system that counts items bought at each store
and to tell how many mugs i have at home idk thats the problem ive been having with my own program. i know its easy and i know the answer i just cant write it

u wanna help me?
and i got these code blocks down i think

Can you add a variable? Maybe one that counts the number of mugs bought?

thats wat im stuck on . when i find one i will put it in my switch statement.

and r u talkin bout something like this

(TOT_MON -= teeshirt)

- keeps track of money spent

(numb_item += 1

i used this statement to keep track of the items bought but i cant figure out how to keep track of the total of each item so at the end of the program i could show the user how many of each item they bought. i just have now just the total of all items and i dont specify which items the user bought at the end.

u get wat im tryin to say?

thats wat im stuck on . when i find one i will put it in my switch statement.

What do you mean "when I find one?" It's your program -- add one.

and r u talkin bout something like this

(TOT_MON -= teeshirt)

- keeps track of money spent

(numb_item += 1

How does that statement count the teeshirts bought? Maybe something like num_teeshirt += 1; might work better?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.