-1
#include <stdio.h>
#include <conio.h>

void main(){
int turn,i=1,num;
char answer;

for(i>0;i++;){
printf("Please enter a number in the range 1-5:");
scanf("%d",&num);

if (num == 1){
    printf("Disconnecting\n");
    continue;
}

else if(num == 2){
continue;
}

else if(num == 3){
    printf("Are you sure you would like to finish your order??? \nplease enter one char:");
    scanf("%c", &answer);
        if(answer == 'y'){
            printf("Canceled");
            break;
        }

        else{
            continue;
    }
}

else if(num == 4){
turn=i-1;
printf("your position in queue is:%d\n",turn);
continue;
}

else if(num == 5){
break;
}

else {
    printf("Wrong input\n");
    continue;
}

}
getch();
}

I'm using c language for this, if You look at the

else if(num == 3)

it should function in a way that when I enter the letter y,Y it will say canceled and end the program and if not it will just reset the loop. now when I use the number 3 and give the variable c the letter 'y' it just says nothing and acts like I gave it the command "continue" + pressed the number 3 again although all I have done is press y or Y and enter. everything else is good. I would be glad if anyone can tell me how to fix that.

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Aviv Gold
  • 5
  • 4

2 Answers2

0

The getch found at the bottom of your main is being used to get order numbers.

Try putting a "getch" in right before you are looking for your y character.

That is to say, something like:

else if(num == 3){
    printf("Are you sure you would like to finish your order??? \nplease enter one char:");
    getch();
    scanf("%c", &answer);
    if((answer == 'y') || (answer == 'Y')) {
        printf("Canceled");
        exit;
    } else {
        continue;
    }
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • that have helped me get it right but now it doesn't mather what letter i use it will allways give me the output canceled even though it should work only with y and Y – Aviv Gold Nov 28 '16 at 04:07
  • now with the new adding it doesn't work ,it is like it was before the getch(); and it says the "exit" is undifined – Aviv Gold Nov 28 '16 at 04:13
0
for(i>0;i++;){
printf("Please enter a number in the range 1-5:");
scanf("%d",&num);getchar();
//... rest of your code
}

use getchar or getch to consume extra newline character

Jamil Farooq
  • 131
  • 2
  • 9