473,503 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I want to do something the user enters the letter Q

1 New Member
Hello,

I need help with this code please.

I want to make this do:
1. when i press Q it will ...

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstdlib>
  4. #include <iomanip>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. char choice='Y';
  13.  
  14. int order = 1;
  15.  
  16. float num1=0, num2=0, num3=0, num4=0, num5=0, total=0;
  17. int num_customers;
  18. int sentinel=0;
  19. const double Price1= 10.35, Price2= 15.35,Price3= 18.25, Price4= 15.55, Price5= 12.55;
  20. double Sale1=0, Sale2=0, Sale3=0, Sale4=0, Sale5=0;
  21.  
  22.  
  23. cout <<"             ¦¦¦¦¦¦¦¦¦¦¦¦¦¦ Hero list ¦¦¦¦¦¦¦¦¦¦¦¦¦\n\n"
  24.      <<"             ¦(1) Spider Man             $10.35\n"  
  25.      <<"             ¦(2) Iron Man             $15.35\n"
  26.      <<"             ¦(3) Captain America        $18.25\n"
  27.      <<"             ¦(4) Hulk                   $15.55\n"
  28.      <<"             ¦(5) Thor                     $12.55\n"
  29.      <<"             ¦(6) Total                            \n";
  30.  
  31. while (order != sentinel)
  32. {
  33.  
  34.  
  35. cout<<"Choose what Marvel hero you would like to order:\n";
  36.  
  37. cin>>order;
  38. switch(order)
  39.             {
  40.                 case 1:
  41.  
  42.                 cout<<"How many  would you like to order:\n";
  43.                 cin>>num1;
  44.  
  45.                 Sale1 = Price1 * num1;
  46.  
  47.                 cout<<"You have ordered:\n\n";
  48.                 cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
  49.                 cout<<"Spider Man toy:"<<setw(6)<<left<< num1 <<setw(16)<<right<< Price1 <<setw(20) <<right<< Sale1<<endl;
  50.  
  51.                 break;
  52.  
  53.  
  54.                 case 2: 
  55.                 cout<<"How Iron Man toy would you like to order:\n";
  56.                 cin>>num2;
  57.  
  58.                 Sale2= Price2 * num2;
  59.  
  60.                 cout<<"You have ordered:\n\n";
  61.                 cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
  62.                 cout<<"Iron Man toy:"<<setw(6)<<left<< num2 <<setw(16)<<right<< Price2 <<setw(20) <<right<<Sale2<<endl<<endl;
  63.  
  64.                 break;
  65.  
  66.  
  67.                 case 3: 
  68.                 cout<<"How many Captain America toy would you like to order:\n";
  69.                 cin>>num3;
  70.  
  71.                 Sale3= Price3 * num3;
  72.  
  73.                 cout<<"You have ordered:\n\n";
  74.                 cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
  75.                 cout<<"Captain America toy:"<<setw(6)<<left<< num3 <<setw(16)<<right<< Price3 <<setw(20) <<right<< Sale3<<endl<<endl;
  76.  
  77.                 break;
  78.  
  79.  
  80.  
  81.                 case 4: 
  82.                 cout<<"How many Hulk toy would you like to order:\n";
  83.                 cin>>num4;
  84.  
  85.                 Sale4= Price4 * num4;
  86.  
  87.                 cout<<"You have ordered:\n\n";
  88.                 cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
  89.                 cout<<"Hulk toy:"<<setw(6)<<left<< num4 <<setw(16)<<right<<Price4 <<setw(20) <<right<< Sale4<<endl<<endl;
  90.  
  91.                 break;
  92.  
  93.  
  94.  
  95.                 case 5: 
  96.                 cout<<"How many Thor toy would you like to order:\n";
  97.                                 cin>>num5;
  98.  
  99.                 Sale5= Price5 * num5; 
  100.  
  101.                 cout<<"You have ordered:\n\n";
  102.                 cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
  103.                 cout<<"Thor toy:"<<setw(6)<<left<< num5 <<setw(16)<<right<<Price5 <<setw(20) <<right<<Sale5<<endl<<endl;
  104.  
  105.                 break;
  106.  
  107.                 case 6:
  108.  
  109.                 total = Sale1 +Sale2 + Sale3 + Sale4 +Sale5;
  110.  
  111.                 cout<<"your total order is:"<< total << endl << endl;
  112.  
  113.  
  114.                 break;
  115.                 default: cout<<"Please use the list as a reference for orders made\n";
  116.  
  117.                 }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.               }
  124.  
  125. system("PAUSE");
  126. return 0;
  127. }
Oct 19 '14 #1
3 1415
weaknessforcats
9,208 Recognized Expert Moderator Expert
When you enter a 1 from a keyboard, you can see the 1 on the screen. This is because you have entered he character 1 rather then the integer 1. That is, '1' versus 1.

Try case '1': rather than case 1: and see if that helps.
Oct 19 '14 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Likewise, if you want to do something in the case where the user enters the character 'Q', you need to add that into your code.

Also, the variable that stores the user input will need to be changed to a type that can hold the type of input provided.


-Frinny
Oct 20 '14 #3
divideby0
131 New Member
If you're wanting to allow alpha-numeric input, then you might try using a std::string or char array for order instead. Your sentinel would need modification though.

A char type would work too, but leaves the little newline gremlin to deal with.
Oct 20 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
2135
by: Xu, Feng | last post by:
Now I am playing with STL. Here is the code: //file name stl.C #include <list> #include <iostream> #include <cstdlib> #include <iterator>
2
1194
by: Robert Smith | last post by:
Why doesnt this code work???? it just stops at the socket() and does not print HI. why is this? #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h>...
5
10035
by: IWP506 | last post by:
10 points (and a cookie) to whoever tells me why this code generates these errors: C:\Programming\Microsoft Visual Studio\MyProjects\HelloWorld\main.c(5) : error C2065: 'cout' : undeclared...
1
2730
by: Matthew Wilson | last post by:
I need to write a function crc(msg, len) that gets a char array of length len and then calculates the crc32 for the code. I don't understand what's going wrong in the code I have. It goes...
1
1285
by: Terry Olsen | last post by:
I'm trying to use Async Socket calls to create a tcp server. It goes into the listening correctly, but when I connect, it crashes with the following exception: An unhandled exception of type...
11
3273
by: Shawn Yates | last post by:
I downloaded TimeLines.zip from (http://www.mvps.org/access/reports/rpt0018.htm) and I think I found a bug in it but I can't seem to fix it. When you open this go to the table and enter a new...
6
1211
by: asdf | last post by:
Members defined in the private section are accessible to other class members. So, I think the following is correct. #include<iostream> using namespace std; class A{ int x; public: int...
5
2612
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
1
1806
by: waqasmgl | last post by:
Hi, I m confused about following ajax code. Where is the problem? Working good on IE but not on FireFox? Please sort it out. <script type="text/javascript"> function loadXMLDoc() { if...
2
1209
by: steve1d | last post by:
What is wrong with the following code : If C.SentOn <> "" Then It keeps erroring. The same code runs perfectly in other modules.
0
7086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7280
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.