943,192 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 378
  • C++ RSS
Feb 8th, 2010
0

create a menu

Expand Post »
How can i make this into a menu where you select a letter and you get a response that reads

you have choosen "a" which is $2.50


/* 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,symb1, symb2, symb3;
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 << " 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 >> mug;
cin >> teeshirt;
cin >> pen;
cin >> quit;
mug = ('A' || 'a');
teeshirt = ('B' || 'b');
pen = ('C' || 'c');
{
if ((mug == 'A') || (mug == 'a'))
{

mug = 2.50;
}
else if ((teeshirt == 'B') || (teeshirt == 'b'))
{

teeshirt = ('B' || 'b');
}
else
{
cout << "Wrong select a letter" << endl;
}
}
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

switch (symb)
{
case 'A':
cout << " A) Mugs $2.50 ";
mug = 2.50;
break;
case 'B':
cout << " B) teeshirt $9.50 ";
teeshirt = 9.50;
break;
case 'C':
cout << " C) Pens .75 cents ";
pen = .75;
break;
case 'D':
cout << " D) Quit" << endl;
quit = 0;
break;
}



return 0;
}
Similar Threads
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010
Feb 8th, 2010
0
Re: create a menu
replace this:
C++ Syntax (Toggle Plain Text)
  1. cin >> mug;
  2. cin >> teeshirt;
  3. cin >> pen;
  4. cin >> quit;
  5. mug = ('A' || 'a');
  6. teeshirt = ('B' || 'b');
  7. pen = ('C' || 'c');
  8. {
  9. if ((mug == 'A') || (mug == 'a'))
  10. {
  11.  
  12. mug = 2.50;
  13. }
  14. else if ((teeshirt == 'B') || (teeshirt == 'b'))
  15. {
  16.  
  17. teeshirt = ('B' || 'b');
  18. }
  19. else
  20. {
  21. cout << "Wrong select a letter" << endl;
  22. }
  23. }
  24. cout.setf(ios::fixed);
  25. cout.setf(ios::showpoint);
  26. cout.precision(2);

with

cin >> symb;

and you've created a menu requesting user input as type char which is stored in symb which is then used as the argument in a switch statement. If you then use something like this:
C++ Syntax (Toggle Plain Text)
  1. case 'A':
  2. case 'a':
  3. cout << " A) Mugs $2.50 ";
  4. mug = 2.50;
  5. break;
  6. .
  7. .
  8. .
  9. default:
  10. cout << "input error, enter only A, B, C or D;
  11. break;
  12.  
you are user friendly in that you let user enter either A or a (or any of the other appropriate letter combinations) and still proceed with the program. (You could also accomplish the same thing by using toupper() to make sure all input is in caps and thereby decrease the number of cases you need to write.)
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Feb 8th, 2010
0
Re: create a menu
im not getting where im sapost to put

cin >> symbol

or am i reading ur remarks wrong, i am new at this. when i compile it and run it, it shows the menu and when i press a letter it says

wrong letter

could you tell me if i got the right set up
Reputation Points: 3
Solved Threads: 0
Junior Poster
timbomo is offline Offline
122 posts
since Feb 2010
Feb 8th, 2010
0
Re: create a menu
Remove everything I said in my earlier post and put this line

cin >> symb;

right after this line

cout << " Enter your letter and press Return when finished" << endl;

and right before this line:

switch(symb)
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Car Class Homework HELP!!
Next Thread in C++ Forum Timeline: Short Shuffle for 1D Array using C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC