jeudi 25 mars 2021

Input control(infinite loop problem,c programming)

I keep getting values ​​as long as the user does not enter a positive integer(and i control if user entered negative values or if user entered an integer). I try to do it without using isdigit, it enters an infinite loop when I enter a character.

int quantity;
        
        printf("Please enter term(s) number");
        scanf("%d",&quantity);
        while( 1){/*while( ( !(quantity>='0' && quantity<='9'))  ||  quantity<0)*/
            if(quantity<0){
                printf("Please enter “positive” term(s) number");
                scanf("%d",&quantity);
            }
        
            if(!(quantity>='0' && quantity<='9')){
                printf("Please enter “numeric” term(s) number");
                scanf("%d",&quantity);
            }
        }

Aucun commentaire:

Enregistrer un commentaire