In my code, if it runs an else statement, then the code ends despite there being other code below that I want to run. This only happens when it runs else statements, not if and else if statements. Is there any way to fix or stop this from happening?
code:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf ("the numbers are %d, %d, %f \n" ,3,4,4.5);
printf ("the character is %c \n", 'h');
int age;
printf ("what is your age? \n");
scanf ("%d",&age);
if (age == 17) {
printf ("You are as old as me! \n");
}
else if (age < 17)
{
printf ("You are younger than me! \n");
if (age == 16)
{
printf ("You can drive. \n");
}
else
{
printf ("You are younger than me and cant drive.");
}
}
else if (age > 100)
{
printf ("Youre probally lying. \n");
}
else {
printf ("Your older than me! \n");
if (age < 21)
{
printf ("youre older than me, but not 21 \n");
}
else
{
printf (" Your older than me and 21 years! \n");
}
int a;
printf (" Enter an integer between 1 and 10. \n");
scanf ("%d", &a);
int b;
printf ("Enter another number between 1 and 10. \n");
scanf ("%d", &b);
int c;
c= (a>b) ? a : b;
printf ("c = %d \n", c);
}
return 0;
}