'does if statment accept this using in C programing?
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
Solution 1:[1]
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.
Solution 2:[2]
#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;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Egor Plotkin |
| Solution 2 | Abdullah Leghari |
