Switch

  • Thread starter Thread starter denis
  • Start date Start date
D

denis

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;
}
 
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.
 
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
 
Back
Top