1

Expected behavior is to take the name as input and run the while loop again but instead it just goes to the next line and does nothing.

#include <iostream>
using namespace std;   
int main()
{
    int ch,mb;
    bool y=true;
    char name;
    cout<<"Enter 1,2 or 3 : ";
    do{
             cin>>ch;
             switch(ch)
             {
                 case 1:
                     cout<<" \n\t 1.ENTER CUSTOMER NAME :";    
                     cin>>name;     
                     continue;
                 case 2:
                     cout<<" \n\t 2.ENTER MOBILE NUMBER:";
                     cin>>mb;
                     continue;
                 case 3:
                     y=false;
            }
      }while(y!=false);
}
Mat
  • 195,986
  • 40
  • 382
  • 396

2 Answers2

0

Use break; instead of continue; break will move execution to the end of the switch.

Edit: I think the issue is that you are just not seeing your prompt again. so move it inside your loop.

Lawrence Ward
  • 529
  • 1
  • 5
  • 17
0

It doesn't "do nothing"; it waits for the next input. Because that's what you told it to do!

If you want to get another prompt, move the cout<<"Enter 1,2 or 3 : "; line inside the loop.


By the way, a char is one byte so that's not really appropriate for reading a whole customer name; furthermore, you should avoid using ints for telephone numbers.

Asteroids With Wings
  • 16,602
  • 2
  • 20
  • 35