# Thread: Computation Loop and duplicate entry error

1. ## Computation Loop and duplicate entry error

I'm stuck! Here is problem I am having: The loop I have made calculates values based off an integer value entered by the user from the keyboard where if they enter the same value from a given interval a warning message is displayed followed by a return to the beginning of the loop.

Here is my code so far:

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

int main(void)

{
int x;
double A, B, C, f1, f2, f3;
printf("Enter a value for A, B, and C:\n");
scanf("%lf %lf %lf", &A, &B, &C);
printf("A = %g \tB = %g \tC = %g\n", A, B, C);

printf("Enter a value for x:\n");
scanf("%d", &x);
printf("x = %d\n",x);

if(x<=0){
printf("Case 1\n");
f1 = (A * pow(x, 3)) - (B * pow(x, 2)) + (x / 1.25);
printf("Value of x = %3d and y = %6.2f\n", x, f1);
}
else if(0<x<1){
printf("Case 2\n");
f2 = A * x - B * pow(x, 4) + pow(C, 2);
printf("Value of x = %3d and y = %6.2f\n", x, f2);
}
else if(x>=1){
printf("Case 3\n");
f3 = A * log(x) - B / x - 2 * A;
printf("Value of x = %3d and y = %6.2f\n", x, f3);
}
}```
Very simple and basic code, as this is my first C/C++ class. The loop works great but I don't know where to go from here to create the additional inputs with the warning message and return to the beginning of the loop.

i hope what I am saying is making sense, I am going on about 4 hours sleep and being up for almost 20 hours at this point (gotta love being a student!).

Any help would be greatly appreciated.

-Dan

2. I think you'd better get some rest.

First of all, there's no loop in the code you posted.

Code:
`else if(0<x<1){`
If you want to check it x is between 0 and 1 you do
Code:
`if (0<x && x<1)`
but since you declared x as an int, x can be 0, it can be 1, but it can't be between 0 and 1.

Popular pages Recent additions