473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I want to do something the user enters the letter Q

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 1408
weaknessforcats
9,208 Expert Mod 8TB
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 Expert Mod 8TB
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 128KB
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
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
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
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
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
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
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
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
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
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
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.