Hey guys

i have a small question here.

float angle0;
printf("\nEnter Original Attack Angle Value in Degree: ");                           //input angle
scanf("%f", &angle0);

            while(angle0<-180 || angle0>180)
            {
            printf("\nEnter Valid Original Attack Angle Value in Degree: ");
            scanf("%f", &angle0);
            }

i dont get it when i put in 180 it still let me continue with the next code segment w/o looping... ~><~

Thanks

Use <= or >= or == operators for checking 180. < operator will check all values less than 180 i.e. upto 179 and > will start from 181.

while(angle0<180 || angle0>180 || angle==180)

btw this is supposed to be in the C section of the forum.

Hammerhead is half right. The explanation is correct, the code is not: while(angle0<180 || angle0>180 || angle==180) This code will always be true. What you are saying is: if Angle is smaller then, equal to or bigger then 180 { do something }

What you mean is: while(angle0<=-180 || angle0>=180 ) This way 180 and -180 are included in the while statement

Sorry I forgot the - sign, my bad.

may e i have caused some confusion here but i dont want my while loop include 180 or -180. Thx for the answers so far.

The problem is i have that code and i dont want 180 or -180 to be included in the while, but when i input 180, the program skips the while loop to continue.

right. So what's the problem then? You said :

> i dont want my while loop include 180 or -180

and earlier:

>when i put in 180 it still let me continue with the next code segment w/o looping...

Am I missing something here?

oh.... it confused me -.-" >< I dunno wat the hell im doing anymore >< Thx for help. I got a new problem here if u guys can help me ^ ^"

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{

float a, b, c;                                                                        //quadratic variables
float disc;
float r1, r2;
float temp;
float angle0= 45;
angle0 = angle0*3.14/180 ;
float x;

a= (-9.8)/(2*(10*cos(angle0)*10*cos(angle0)));                                       //quadratic
b= tan(angle0);
c= 300;

disc = b*b - 4*a*c;

if (disc > 0.0)
{
temp = sqrt(disc);
r1 = (-b + temp)/(2.0*a);
r2 = (-b - temp)/(2.0*a);

if (r1 < r2)
{
r2 = x;
}
else r1 = x;

}

else
x= -b/(2.0*a);                                                                           //end quadratic


printf(" %d",x);
printf("\n %f",a);
printf("\n %f",b);
printf("\n %f",c);
printf("\n %f",disc);
printf("\n %f",temp);
printf("\n %f",r1);
printf("\n %f",r2);
scanf(" %c");
}

this program suppose to calculate the quadratic's results, r1 and r2.
x is assigned the bigger of the two.
but r2 comes out weird.

r1 supposed to be -50.46
r2 supposed to be 60.66

if (r1 < r2)
{
r2 = x;
}
else r1 = x;

}

This part is wrong. It's not r2 = x ( assign the value of x to r2) but x=r2 (assign the value of r2 to x)
so:

if (r1 < r2)
    x = r2;
else 
    x = r1;

And please next time you post code, please use code tags: [code=cpp] // code here [/code]

Thx a lot niek_e . Im too tired to find that silly mistake lol. ^ ^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.