Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am still new in C language, i have written this code #include <stdio.h> #inclu

ID: 3753222 • Letter: I

Question

I am still new in C language, i have written this code

#include <stdio.h>
#include <stdlib.h>

int main ()
{
int age;
printf(" Please enter your age ");
scanf ("%d",&age);
if(age > 18);
{
printf ("Your are older than 18");
}
if (age<18);
{
printf ("You are less than 18 years");
}
if (age==18);
{
printf ("You are equal to 18");
}
}

And on code blocks i am getting this feedback

if statement.c-Code: Blocks 17.12 File Edit View Search Project Build Debug Fortran woSmithTools Tools+Plugins DoxyBlocks Settings Help global> s ZOUif statement.exe Please enter your age 21 Your are older than 18You are less than 18 yearsYou are equal to 18 Process returned (ex execution time 2.664 s Press any key to continue Projects Workspac +messages > Cscope Debugge File Line Hessag Bu1iid tiie: "no target" in "no project" (cospiler: unknoun) Build finished : 0 error(s), 0 w&rning [s) [0 minute (s), 0 5econd(s)) GAUsers Fazhang ts ZOUif statement.c CIC++ Windows (CR+LF default Line 8, Col 19, Pos 124 Insert Read/Write default off dy) ENG 13:22 24/9/2018 4

Explanation / Answer

Below is the solution:

If checking the multiple condition every time the if statement is executed.

Try to pu if...Else if ...Else if ...Else statement to get the correct result.

Below is the correct auction:


#include <stdio.h>
#include <stdlib.h>

int main ()
{
int age;
printf(" Please enter your age ");
scanf ("%d",&age);
if(age > 18)
{
printf ("Your are older than 18");
}
else if (age<18)
{
printf ("You are less than 18 years");
}
else if (age==18)
{
printf ("You are equal to 18");
}
return 0;
}

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote