I wrote the code below and I have a problem I don't know how to separate the first if and the second if, thanks for the help in advance
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
printf("welcome user\n");
printf("please answer this following questions\n");
printf("what is your age");
int age;
scanf("%d", &age);
printf("your age is %d\n", age);
int main();
{
int age = 30;
if (age < 30);
printf("you are yong i like that\n ");
int main();
if (age > 30);
printf("you are to old\n ");
printf("its ok you still human\n");
printf("XD\n");
}
}
CodePudding user response:
I think you probably want your code to be revised to somewhere along the lines of this:
Remove these extra unnecessary main() and have if and else if block or just else block contained in braces. Also, although not required for correct code execution, indent for better readability. And finally delete the int age = 30;
line.
int main()
{
printf("welcome user\n");
printf("please answer this following questions\n");
printf("what is your age");
int age;
scanf("%d", &age);
printf("your age is %d\n", age);
if (age < 30) // if more than one line, must contain if block within braces
printf("you are yong i like that\n ");
else if (age > 30) {
printf("you are to old\n ");
printf("its ok you still human\n");
printf("XD\n");
}
}
CodePudding user response:
One addition to @Asphodel if I may. You might want to add a condition for age==30 somewhere
if(age <= 30)
or
if(age => 30)
or another else branch
else if(age == 30)