# Thread: Having Trouble with a nested if else if statement.

1. ## Having Trouble with a nested if else if statement.

I am working on a project for school and I am having difficulty getting this section of code to give the desired output. Can someone give me alittle guidance? No matter what value I input I get the first printf statement as a result.

if (n<5.0)
printf("There will be little or no damage with this earthquake.\n\n", n);

else if (n>=5.0 && n<5.5)
printf("There will be some damage with this earthquake.\n\n", n);

else if (n>=5.5 && n<6.5)
printf("There will be serious damage with this earthquake: walls may crack or fall.\n\n", n);

else if (n>=6.5 && n<7.5)
printf("Disastrous results will occur with this earthquake: houses and buildings may collapse.\n\n", n);

else
printf("Catastrophic results will occur with this earthquake: most buildings will be destroyed.\n\n", n);

2. No matter what value I input I get the first printf statement as a result.
Usually that symptom indicates you have a semicolon after your if-statement. Alternatively, you should check that you are assigning something to n.

3. Here is what I have written so far, everything is compiling fine. Thanks for the quick response.

Code:
```#include<stdio.h>

/* Function prototypes*/
void instruct_user(void);

int
main(void)
{
double n; /* Represents the number registered on Richter Scale */

/* Display user instructions.*/
instruct_user();

/* Get user input*/
printf("Enter the number registered on the Richter scale and press return> ");
scanf("%1f", &n);

/*The decision making process based on a Multiple-Alternative Decision order of conditions*/
/*A switch statement could not be used when inputing type double there for if else is more appropriate.*/

if (n<5.0)
printf("There will be little or no damage with this earthquake.\n\n", n);

else if (n>=5.0 && n<5.5)
printf("There will be some damage with this earthquake.\n\n", n);

else if (n>=5.5 && n<6.5)
printf("There will be serious damage with this earthquake: walls may crack or fall.\n\n", n);

else if (n>=6.5 && n<7.5)
printf("Disastrous results will occur with this earthquake: houses and buildings may collapse.\n\n", n);

else
printf("Catastrophic results will occur with this earthquake: most buildings will be destroyed.\n\n", n);

return (0);
}
/* Displays user instructions*/
void
instruct_user(void)
{
printf("This program will take input from the user and provide the user with the affects\n");
printf("of an Earthquake based on it's Richter scale.\n\n");
}```

4. Code:
`%lf`
and
Code:
`%1f`
are not the same thing.

5. Thanks so much I have been looking at this for a couple of hours, as I am a rookie I guess this would classify as a rookie mistake
Thanks again