Hello,
I need help with this code please.
I want to make this do:
1. when i press Q it will ... - #include <iostream>
-
#include <cctype>
-
#include <cstdlib>
-
#include <iomanip>
-
-
-
using namespace std;
-
-
-
int main()
-
{
-
char choice='Y';
-
-
int order = 1;
-
-
float num1=0, num2=0, num3=0, num4=0, num5=0, total=0;
-
int num_customers;
-
int sentinel=0;
-
const double Price1= 10.35, Price2= 15.35,Price3= 18.25, Price4= 15.55, Price5= 12.55;
-
double Sale1=0, Sale2=0, Sale3=0, Sale4=0, Sale5=0;
-
-
-
cout <<" ¦¦¦¦¦¦¦¦¦¦¦¦¦¦ Hero list ¦¦¦¦¦¦¦¦¦¦¦¦¦\n\n"
-
<<" ¦(1) Spider Man $10.35\n"
-
<<" ¦(2) Iron Man $15.35\n"
-
<<" ¦(3) Captain America $18.25\n"
-
<<" ¦(4) Hulk $15.55\n"
-
<<" ¦(5) Thor $12.55\n"
-
<<" ¦(6) Total \n";
-
-
while (order != sentinel)
-
{
-
-
-
cout<<"Choose what Marvel hero you would like to order:\n";
-
-
cin>>order;
-
switch(order)
-
{
-
case 1:
-
-
cout<<"How many would you like to order:\n";
-
cin>>num1;
-
-
Sale1 = Price1 * num1;
-
-
cout<<"You have ordered:\n\n";
-
cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
-
cout<<"Spider Man toy:"<<setw(6)<<left<< num1 <<setw(16)<<right<< Price1 <<setw(20) <<right<< Sale1<<endl;
-
-
break;
-
-
-
case 2:
-
cout<<"How Iron Man toy would you like to order:\n";
-
cin>>num2;
-
-
Sale2= Price2 * num2;
-
-
cout<<"You have ordered:\n\n";
-
cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
-
cout<<"Iron Man toy:"<<setw(6)<<left<< num2 <<setw(16)<<right<< Price2 <<setw(20) <<right<<Sale2<<endl<<endl;
-
-
break;
-
-
-
case 3:
-
cout<<"How many Captain America toy would you like to order:\n";
-
cin>>num3;
-
-
Sale3= Price3 * num3;
-
-
cout<<"You have ordered:\n\n";
-
cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
-
cout<<"Captain America toy:"<<setw(6)<<left<< num3 <<setw(16)<<right<< Price3 <<setw(20) <<right<< Sale3<<endl<<endl;
-
-
break;
-
-
-
-
case 4:
-
cout<<"How many Hulk toy would you like to order:\n";
-
cin>>num4;
-
-
Sale4= Price4 * num4;
-
-
cout<<"You have ordered:\n\n";
-
cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
-
cout<<"Hulk toy:"<<setw(6)<<left<< num4 <<setw(16)<<right<<Price4 <<setw(20) <<right<< Sale4<<endl<<endl;
-
-
break;
-
-
-
-
case 5:
-
cout<<"How many Thor toy would you like to order:\n";
-
cin>>num5;
-
-
Sale5= Price5 * num5;
-
-
cout<<"You have ordered:\n\n";
-
cout<<left<<setw(15)<<"ITEM"<<right<<setw(10)<<"QUANTITY"<<right<<setw(15)<<"UNIT PRICE"<<right<<setw(20)<<"AMOUNT OF SALE\n";
-
cout<<"Thor toy:"<<setw(6)<<left<< num5 <<setw(16)<<right<<Price5 <<setw(20) <<right<<Sale5<<endl<<endl;
-
-
break;
-
-
case 6:
-
-
total = Sale1 +Sale2 + Sale3 + Sale4 +Sale5;
-
-
cout<<"your total order is:"<< total << endl << endl;
-
-
-
break;
-
default: cout<<"Please use the list as a reference for orders made\n";
-
-
}
-
-
-
-
-
-
}
-
-
system("PAUSE");
-
return 0;
-
}
3 1415
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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>
|
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>...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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)...
|
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...
|
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.
|
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...
| |
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |