# Thread: Computing the value of a function

1. ## Computing the value of a function

Hi there,

I'm having trouble getting the desired output. whenever I enter a number, my program just freezes and doesn't do anything. if it does do something, it's always the number I input. e.g: if I put in 2, it will give me 2 in return.

Here's the code
Code:
```
#include <stdio.h>
#include <math.h>

int main(void)
{
double x;

printf("Enter a number x: ");
scanf("%lf\n", &x);
if ((x*x-5*x) == 0)  {
printf("f(x) is not defined\n");
}
else if ((3*x + 6) < 0)  {
printf("f(x) is not defined\n");
}
else (((1+(x*x)/sqrt(3*x+6))/(x*x-5*x)));  {
printf("f(x) = %lf\n", x);
}
return(0);
}```
Should I implement a function to call on? any other type of loop maybe?

2. Code:
```else (((1+(x*x)/sqrt(3*x+6))/(x*x-5*x)));  {
printf("f(x) = %lf\n", x);
}```
This is attached to the else. This happens regardless of all of your if checks.

Quzah.

3. Ok, so I revamped my code a little bit:

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

double function(double x);

int main()
{
double x;

printf("Enter a number x: ");
scanf("%lf\n", &x);

if (x != 0 || x > -2)  {
printf("f(x) = %lf\n", function(x));
}
else   {
printf("f(x) is not defined\n");
}
return(0);
}

double function(double x)
{
return (((1+(x*x)/sqrt(3*x+6))/(x*x-5*x)));
}```
So here's my problem now: It will ask me to enter a value of x, and I do. but I have to enter another number after it in order for the program to give me output. This is what it looks like:
Code:
```Enter a number x: 2.74 //This doesn't do anything
2.74 //This is the number that gets the program to give output
f(x) = -0.482997```
What am I doing wrong?

4. Ditch the newline in the scanf.

5. Thank you! It works fine now.

edit: I also changed the || to &&, and the program gives what I need now.