Uses conditional operator to check result - C Operator

C examples for Operator:Conditional Operator

Description

Uses conditional operator to check result

Demo Code

#include <stdio.h>

#define COVERAGE 350       // square feet per paint can

int main(void)
{
    int sq_feet;//www .  j a  va2s  .c  om
    int cans;
    
    printf("Enter number of square feet:\n");
    while (scanf("%d", &sq_feet) == 1)
    {
        cans = sq_feet / COVERAGE;
        cans += ((sq_feet % COVERAGE == 0)) ? 0 : 1;
        printf("You need %d %s of paint.\n", cans, cans == 1 ? "can" : "cans");
        printf("Enter next value (q to quit):\n");
    }
    
    return 0;
}

Result


Related Tutorials