'How to separate two if statements in my code?
I wrote the code below and I have a problem I don't know how to separate the first if and the second if.
#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");
}
}
Solution 1:[1]
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");
}
}
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 | drescherjm |
