473,883 Members | 2,205 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 6867
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
4544
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 (reg.php). The data are then inserted into a table (reg) in MS SQL server. I have declared the...
1
30378
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>" field indicates the 20 characters of the SQL statement that preceded the token
12
3245
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
2
1331
by: iincity | last post by:
hi,all, please see following: int index = 0 switch(index){ case 0 - 10: break; default: break;
5
8775
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 catch statement, and/or, after the USING statement ends, the sql connection object is automatically...
3
1542
by: ken | last post by:
any function is equal to "Switch" in Java with VB thank heaps
6
2771
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 specifically tell it what my compilers are as follows................. C:\Program...
0
1375
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. However, if I attempt to insert (i), find (f), or delete (d) it loops back to the menu *but*...
7
2750
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
9953
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11166
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10868
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10422
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9588
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4231
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.