0

I have faced an issue while creating a program where if user input would 'Y' or 'y' the program would start again using goto statement but while running the code I found my compiler is ignore or what that scanf line which allows to take input of the character is not accepting any input sorry if my question is wrong but I am pretty new c programing

#include <stdio.h>

int main()
{
    int num1, num2;
    char looping;

AGAIN:
    printf("ENTER FIRST NUMBER FOR ADDITION\n");
    scanf("%d", &num1);

    printf("ENTER SECOND NUMBER FOR ADDITION\n");
    scanf("%d", &num2);

    printf("ADDITION OF TWO NUMBERS IS %d\n", num1 + num2);

    printf("DO YOU WANT TO RUN LOOP AGAIN ?\nENTER Y FOR YES AND N FOR NO\n");
    scanf("%c", &looping);

    if (looping == 'Y' || looping == 'y')
    {
        goto AGAIN;
    }
    else
    {
        goto EXIT;
    }

EXIT:
    printf("EXITING");

    return 0;
}
  • 3
    I suggest replacing `goto` with a `while` loop – Eugene Sh. Nov 09 '21 at 16:31
  • 3
    As for your problem, replace `"%c"` with `" %c"` - note the whitespace, to consume the newline character. – Eugene Sh. Nov 09 '21 at 16:32
  • 1
    Please [edit] your question and add the input you use, the actual output/behavior you get and the expected output/behavior. A `do` ... `while` loop is the right thing when you want to do something at least once and afterwards check if you want to repeat. – Bodo Nov 09 '21 at 16:33
  • 1
    choose your dupe: https://stackoverflow.com/search?q=%5Bc%5D+scanf+getting+skipped – yano Nov 09 '21 at 16:39
  • 1
    @yano I chose a dupe – user253751 Nov 09 '21 at 17:06

0 Answers0