Your code has several problems:
Major flaws
- it features invalid syntax: the
Quote:
if ("%lf", &x, 0<=x<=90)
line is illegal code in C
, as k5054 pointed out, this is (though not extremely useful) legal C
code. - It lacks input validation.
Minor problems
- Type mismatches:
0, 90, ..
are integer constant literals, your code compares them with a double
variable (while this will work due to C
type promotion rules, it is incorrect and misleading). - Incorrect handling of ranges (corner cases), for instance
Quote:
if ("%lf", &x, 0<=x<=90){
and Quote:
if ("%lf", &x, 90<=x<=180){
would both handle x==90
. - Your code uses an old, non standard header (
conio.h
).
Try
#include <stdio.h>
int main()
{
double x;
printf ("Please enter the angle value in degrees:\n");
if ( scanf("%lf", &x) != 1 )
{
printf("invalid entry, please enter the angle degrees\n");
return -1;
}
if ( x < 0.0 || x >= 360.0)
{
printf("out of range, please enter a number in [0,360) range\n");
return -1;
}
if ( x < 90.0 )
printf("everything is positive\n");
else if ( x <180 )
printf("sin is positive while cos, tg, ctg are negative\n");
else if ( x < 270 )
printf("sin and cos are both negative while tg, ctg are both positive\n");
else
printf("sin, tg, ctg are negative while cos is positive\n");
printf("please enter a character to exit\n");
getchar();
return 0;
}