Initial problem in C

Asked

Viewed 56 times

-2

I’m having trouble with code output, I come from Python and I’m a little lost in the C language, what happens is this: I run the code but it simply ignores the input of the condition variable, it doesn’t let the user dictate the value , simply jumps and falls in "Type to see even numbers "...
I’ve tried a lot and I can’t fix it, I’ll keep waiting for a hint.

#include <stdlib.h>
#include <stdio.h>

int main(){

    int quant;

    char decisao = 's';

    while(decisao){
        printf("Digite até onde deseja ver pares : ");
        scanf("%d",&quant);

        for(int num = 0; num < quant ; num = num + 2)   {
            printf("%d\n",num);
        }
        printf("DESEJA CONTINUARR ?\n");
        fflush(stdin);
        scanf("%c",&decisao);
    }
}

1 answer

1


The scanf is reading the enter you pressed while typing a number.

To ignore whitespace, use a space before %c.

scanf(" %c",&decisao);

  • Thanks help Vinicius, it worked perfectly :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.