Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-27-2003, 10:05 AM   PM User | #1
Xiang
New Coder

 
Join Date: Jul 2002
Location: Malaysia
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Xiang is an unknown quantity at this point
function

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
Xiang is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:07 AM.


Advertisement
Log in to turn off these ads.