473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Switch

What am I Doing incorect? My choice value is 2, but for
some reason cout is not printing the message?
switch (choice)
{
case 1:cout<<"Enter value in Fahrenheit:" ;break;
case 2:cout<<"Enter value in Centigrade:";break;
case 3:cout<<"Thank you for using this program.";break;
default: break;
}
Nov 16 '05 #1
2 1515
If it does not print out the message associated with case 2, then what
message does it print. And try printing out the value of choice to see if it
really is 2. Your code is okay, there is nothing wrong in the snippet you've
shown us.

--
Regards,
Nish [VC++ MVP]

"denis" <de***@yahoo.com> wrote in message
news:0f****************************@phx.gbl...
What am I Doing incorect? My choice value is 2, but for
some reason cout is not printing the message?
switch (choice)
{
case 1:cout<<"Enter value in Fahrenheit:" ;break;
case 2:cout<<"Enter value in Centigrade:";break;
case 3:cout<<"Thank you for using this program.";break;
default: break;
}

Nov 16 '05 #2
Hi,

you missed to write an enter code for the value in
Fahrenheit. If you want the switch function to proceed
with 2, you first have to read the Fahrenheit value into a
variable. Consider the following:

case 1:
cout<<"Enter value in Fahrenheit:";
cin >> value_in_fahrenheit;
break;
case 2: ....

If this is what you intended to do, then it should work.
But be carefull with the cin stream. If you press enter on
the console when typing in your value, this may also skip
the 2nd case branch because the variable value is still in
the input puffer of your system.
Compare the getche() and getch() functions in C.
Regards.
Alex
-----Original Message-----
What am I Doing incorect? My choice value is 2, but for
some reason cout is not printing the message?
switch (choice)
{
case 1:cout<<"Enter value in Fahrenheit:" ;break;
case 2:cout<<"Enter value in Centigrade:";break;
case 3:cout<<"Thank you for using this program.";break;
default: break;
}
.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
5
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
65
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
11
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
12
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
7
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
11
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the...
0
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
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,...
0
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...
1
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
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
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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.