Using a _Bool variable - C Data Type

C examples for Data Type:bool

Description

Using a _Bool variable

Demo Code

#include <stdio.h>

int main(void){
    long num;//from   www  .java2s.c  o m
    long sum = 0L;
    bool input_is_good;
    
    printf("Please enter an integer to be summed ");
    printf("(q to quit): ");
    input_is_good = (scanf("%ld", &num) == 1);

    while (input_is_good){
        sum = sum + num;
        printf("Please enter next integer (q to quit): ");
        input_is_good = (scanf("%ld", &num) == 1);
    }
    printf("sum: %ld.\n", sum);
    
    return 0;
}

Result


Related Tutorials