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

Home Posts Topics Members FAQ

Help me in this "Switch Statement" Puzzle !

NewYorker
13 New Member
Write a switch statement that tests the value of the char variable response and performs the following actions:
if response is y , the message Your request is being processed is printed
if response is n , the message Thank you anyway for your consideration is printed
if response is h , the message Sorry, no help is currently available is printed
for any other value of response , the message Invalid entry; please try again is printed


__________________________________________________ ________________

I answered:

switch (response)
{
case 0:
if(response=='y')
cout<< "Your request is being processed"<< endl;
break;

case 1:
if(response=='n')
cout<<" Thank you anyway for your consideration" << endl;
break;

case 2:
if(response=='h')
cout<<"Sorry, no help is currently available" << endl;
break;

case 3:
cout<<"Invalid entry; please try again" << endl;
break;
}


Result: Incorrect !
Message:
You are not displaying anything on the screen for any of the different values of response listed in the instructions.
Remember what keyword to use for any other value of response.
You don't seem to be using your cases properly. Don't forget about quotes.
Nov 16 '06 #1
2 6846
smartway
24 New Member
switch case structure is replacemet for if-else if....-else structure

try the following code
switch (response)
{
case 'y':
cout<< "Your request is being processed"<< endl;
break;

case 'n':
cout<<" Thank you anyway for your consideration" << endl;
break;

case 'h':
cout<<"Sorry, no help is currently available" << endl;
break;

default:
cout<<"Invalid entry; please try again" << endl;
break;
}
Nov 16 '06 #2
NewYorker
13 New Member
Awesome !

Really A Smart Way !

Regards.


switch case structure is replacemet for if-else if....-else structure

try the following code
switch (response)
{
case 'y':
cout<< "Your request is being processed"<< endl;
break;

case 'n':
cout<<" Thank you anyway for your consideration" << endl;
break;

case 'h':
cout<<"Sorry, no help is currently available" << endl;
break;

default:
cout<<"Invalid entry; please try again" << endl;
break;
}
Nov 16 '06 #3

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

Similar topics

1
4527
by: newbie_mw | last post by:
Seems my post was buried in more cries for help :-) I will try again. It's probably a very novice question so please take a look! Thanks!...
1
30128
by: Najm Hashmi | last post by:
Hi all , I am trying to create a store procedure and I get the following error: SQL0104N An unexpected token "END-OF-STATEMENT" was found following "END". Expected tokens may include: "JOIN...
12
3201
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
2
1312
by: iincity | last post by:
hi,all, please see following: int index = 0 switch(index){ case 0 - 10: break; default: break;
5
8728
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement....
3
1522
by: ken | last post by:
any function is equal to "Switch" in Java with VB thank heaps
6
2749
by: Sile | last post by:
Hello, I'm trying to get f2py working from the command line on windows XP. I have mingw32 as my C complier (after some advice on a previous thread) and Compaq Visual Fortran 6.5. Changing my C...
0
1357
by: Sudz28 | last post by:
Greetings! I am attempting to write a program that will allow a user to manipulate data read from a file, and am obviously in no way near finished. However, one problem I'm having that I don't...
7
2727
by: trbjr | last post by:
There is something I don't understand about the syntax of the SWITCH command. Here is the code that does not work: switch (msgtype == ) { case '0' : title = "Error Condition -- see...
0
7089
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
7282
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
6995
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
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4678
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
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
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
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.