Xiang
02-27-2003, 10:05 AM
Dear sir,
I want to write a program that accepts any number from the keyboard. The number should be sent to the function int_test(), which returns either the integer value, or -1 if the number is negative, or floating point if it is nonnegative but not an integer. Input should continue until zaro is input. In my program, I can't display the output in properly.
int int_test(int y);
int x;
void main(void)
{
clrscr();
do{
printf("Your number: ");
fflush(stdin);
scanf("%i", &x);
int_test(x);
} while(x != 0);
getch();
}
int int_test(int y)
{
if (y == x)
printf("The number is %i \n", y);
else
if (y <= -1)
printf("The number is negative \n");
else
if(y != y)
printf("The number is not an integer\n");
return y;
}
The actual output:-
Your number: 48
The number is 48
Your number: -14.3
The number is negative
Your number: 12.562
The number is not an integer
Your number: 0
Thanks,
Xiang
I want to write a program that accepts any number from the keyboard. The number should be sent to the function int_test(), which returns either the integer value, or -1 if the number is negative, or floating point if it is nonnegative but not an integer. Input should continue until zaro is input. In my program, I can't display the output in properly.
int int_test(int y);
int x;
void main(void)
{
clrscr();
do{
printf("Your number: ");
fflush(stdin);
scanf("%i", &x);
int_test(x);
} while(x != 0);
getch();
}
int int_test(int y)
{
if (y == x)
printf("The number is %i \n", y);
else
if (y <= -1)
printf("The number is negative \n");
else
if(y != y)
printf("The number is not an integer\n");
return y;
}
The actual output:-
Your number: 48
The number is 48
Your number: -14.3
The number is negative
Your number: 12.562
The number is not an integer
Your number: 0
Thanks,
Xiang