Hi, I have a code, but I don't get what I'm doing wrong, can you please help me with this

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

my code is:

switch(response){
case 'y': response;
case 'n': response;
case 'h': response;
break:;
}

Hi, I have a code, but I don't get what I'm doing wrong, can you please help me with this

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

my code is:

switch(response){
case 'y': response;
case 'n': response;
case 'h': response;
break:;
}

Why you are not using break statement for each of the case statement..?

oh I forgot about that;

ok so I have this, but I'm missing what goes in the response

switch(response){
case 'y':;
break;
case 'n':;
break;
case 'h':;
break:;
}

Member Avatar for GreenDay2001

the syntax for switch case is :

switch(data type)
{
      case value1: statements; break;
      case value2: statements; break;
      .............................................
      ..............................................
      case valuen: statements; break;
      default: statements;
}

so you could write statements for every case. In this case you need to put the output on screen so you could simply use cout. Default contains the statements to be executed when none of the case matches the value of the variable. So now you should try yourself writing this program using the above case syntax.

ok so I write the statements after the cout, and that's it? I tried it, and it doesn't work...:sad:


switch(response){
case 'y':cout<<"";
break;
case 'n':cout<<"";
break;
case 'h':cout<<"";
break:;
}

Thanks alot, It took a while, but I got what you meant....Thanx:lol:


Finished code:

switch(response)
{
case 'y': cout<<"Your request is being processed";
break;
case 'n': cout<<"Thank you anyway for your consideration "; break;
case 'h': cout<<"Sorry, no help is currently available";
break;
default: cout<<"Invalid entry; please try again";
}

Please use code tags while posting code since it preserves fomatting and makes the code more readable by syntactic highlighting..

Read the forum annoucements for more details..

how to quit the program using switch statement???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.