Home > Mobile >  does if statment accept this using in C programing?
does if statment accept this using in C programing?

Time:03-27

This code prints age and declaire it old or not old!!!!

#include<stdlib.h>
 int main(int argc, char *argv[]){
///simple if statment 
int age = 0;
printf("quel age avez-vous ");
///can i use if statment like this ???????????????????
if(age >= 18)
if(age < 18)

printf ("votre age est %d donc vouse etes majeur ! \n");
scanf ("%d", &age);
printf ("votre age est %d donc vous etes pas majeur !\n");
scanf ("%d", &age);

return 0;
}

/// gives many worning but work even so in IDE

CodePudding user response:

If I got it correctly you are trying to check if "age >= 18" and just after that if "age < 18".

You may do it, but it not make sense due to second condition always equals to false. Also I wouldn't be surprised if some of IDE's will just cut it off, due to this stage will never be reached.

CodePudding user response:

#include<stdlib.h>

int main(int argc, char *argv[])
{
    //simple if statement 
    
    int age = 0;
    printf("quel age avez-vous ");
    scanf ("%d", &age);
    
    
    if(age >= 18)
        printf ("votre age est %d donc vouse etes majeur ! \n", age);
    
    if(age < 18)
        printf ("votre age est %d donc vous etes pas majeur !\n", age);

    return 0;
}
  • Related