473,569 Members | 2,701 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 6851
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
4529
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! ----------------------------------------------------------------- I created a sign-up sheet (reg.html) where people fill in their first name, last name, email, etc. The data are then sent to a PHP script...
1
30188
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 <joined_table> Explanation: A syntax error in the SQL statement was detected at the specified token following the text "<text>". The "<text>"...
12
3210
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
2
1316
by: iincity | last post by:
hi,all, please see following: int index = 0 switch(index){ case 0 - 10: break; default: break;
5
8735
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. This works fine. When i try to implement the "SqlTransation" class, the code does not work as the SqlTransation object is out-of-scope in the...
3
1529
by: ken | last post by:
any function is equal to "Switch" in Java with VB thank heaps
6
2757
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 complier reduced my errors but I'm still having trouble. I think I have all the correct paths set but I'm not sure. F2PY gets further when I...
0
1361
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 understand is with my switch subroutine. In the below code, if I select "d" or anything that is an invalid response, it loops correctly back to the menu....
7
2737
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 Tom "; break; case '1' : title = "Domestic Program";
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2113
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 we have to send another system
1
1212
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.