Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
#include <stdio.h>
void main(void)
{
float value;
int int_test(float);
printf("Your Number: ");
scanf("%f", &value);
while (value !=0)
{
int_test(value);
printf("Your Number: ");
scanf("%f", &value);
}
}
int int_test(float a)
{
int result;
if (a<0)
{
printf("The number you have entered is negative\n");
result = -1;
return result;
}
else if ((a>0) && (int)(a-a>0))
{
printf("The number you have entered is not an integer\n");
result = 0;
return 0;
}
else
{
printf("The number you have entered is %g\n",a);
return a;
}
}


I got an error that when i key in the float number it should be giving me the output screen that the number is not an integer, but it show the DIRECTLY FLOAT NUNMBER..may i know where is the error of my coding?
Posted
Comments
Albert Holguin 3-Apr-11 22:09pm    
not sure i understand what you say your error is, there's a lot of things wrong with this code

1 solution

This statement doesn't make any sense:
(int)(a-a>0)

I think what you want is:
((a-(int)a)>0)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Apr-11 3:31am    
Good catch, a 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900