i keep getting 4 errors on here and i cant figure out what they are I followed the syntax i believe

}
        if (( tot_mon <= 0.0f && orig_mon <= 0.0f))
            cout << "You need more cash, you dont have enough\n" << endl;
        else
            if (tot_mon <= 0);
                cout << " You have spent " << curr_cash << " and have purchased " << numb_item << " today.\n " << endl;
            else
                if (symb2 = 'N' || 'n')
                    cout << " Thank you for shopping \n";
                    cin >> symb2;
                    else
                        if (symb2 = 'Y' || 'n')
                            cout << " Please choose A, B, or C to continue. \n";
                            cin >> symb2;

1.) Read this.
2.) Answer these:
A.) What are you trying to accomplish? We can't help if we don't know that.
B.) What are the errors you are getting? Again, can't help if we don't know.
C.) Why is there a '}' on line 1? What is the scope that that is closing?
3.) Line 5 is definitely not right. There should NEVER be a semi-colon (';') in that location.
4.) Your else statements don't seem to be matching up correctly. Check your blocking (use of '{' and '}').

Once you do that, we may be able to help you.

Edited 6 Years Ago by Fbody: n/a

Use brackets for your if/else clauses:

if (something)
  {
    ...
   }
else if (something_else)
   {
     ...
    }

You have statements that should be in the conditional clauses, but aren't, making the compiler see unmatched 'else' statements. You are also putting semicolons where they don't belong. Read the nice error and warning messages your compiler is spitting out.

Edited 6 Years Ago by rdrast: n/a

{ //start body of loop
  ....
  case 'A':
    if money_left more than  cost-of-A
     money-left -= cost-of-A
     increment number-of-items-bought-today
     money-spent += cost-of-A
   else
     sorry you do not have enough money to buy this
   break;
   ....
 } //end switch
  if money-left not enough to by cheapest item available
    sorry you do not have enough money to buy any more items.
    change flag to drop out of loop
}//end loop
thank you for shopping.  you have spent money-spent on numb-items and have money-left.

this is what im tryin to do. i am stuck on number 6 thats what i was attempting to do

You are to write a program that:
1. Shows the user how much money they have and lists the items they can choose to buy, plus an option to quit.
2. Accepts the user’s choice of which item to buy. If the user chose to quit, then go to step #6.
3. If the user can afford to buy one or more of the items they chose to buy, ask them how many they want. Once they have chosen how many they want, subtract the amount it costs to buy those items from their current money amount. Make sure to keep track of how many of each item they buy.
4. Go back to step #1 unless the user does not have enough money to buy anything else. If they don’t have enough money, go to step #5.
5. Because the user ran out of money, tell them that they can’t afford any more stuff.
6. Show the user a final report that tells them how much money they have left over and how many of each item they bought. Then quit the program.

but this is my program you can run it. if u want

char symb, symb2;
    double	mug=2.50f,teeshirt=9.50f,pen=0.75f,tot_mon=30.0f,curr_cash=+0.0f, orig_mon=0.0f;
    int numb_item = 0;

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) && (numb_item += 1);
            cout << " You have " << tot_mon << " remaining and have purchase " << numb_item << " items " << endl << endl;
            break;
            case 'B':
            case 'b':
            cout << " You have choosen B) teeshirt for $9.50 " << endl;
            (tot_mon -= teeshirt) && (numb_item += 1);
            cout << " You have " << tot_mon << " remaining and have purchase " << numb_item << " items " << endl << endl;
            break;
            case 'C':
            case 'c':
            cout << " You have choosen C) Pens for .75 cents " << endl;
            (tot_mon -= pen) && (numb_item += 1);
            cout << " You have " << tot_mon << " remaining and have purchase " << numb_item << " items " << endl << endl;
            break;
            case 'D':
            case 'd':
            cout << " You have choosen D) which means you want to Quit" << " You have " << tot_mon << " leftover " << endl;
            orig_mon <= 0;
            break;
            default:
            cout << "Wrong please select A, B, C, or D to quit. " << endl;
       }
if (( tot_mon <= 0.0f && orig_mon <= 0.0f))
            cout << "You need more cash, you dont have enough\n" << endl;
        else
            if (tot_mon <= 0);
                cout << " You have purchased " << numb_item << " items today.\n ";
        } while ( tot_mon >= 0.0f );
        cout << "Thank you for shopping.\n";
   	return 0;

To keep track of how many of each item the user buys you need to keep separate counts for each one, very similar to what you've done for numb_items, which keeps track of how many items total have been purchased.

This article has been dead for over six months. Start a new discussion instead.