By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,824 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,824 IT Pros & Developers. It's quick & easy.

Function to determine non-negative int

P: 1
Write this program using functions.

Write a program that accepts any number from the keyboard and tells you whether it is a nonnegative integer. The number should be sent to the function int_test( ), which returns either the integer value, or -1 if the number is negative, or zero if it is nonnegative but not an integer. Inputs should continue until zero is input.

Functions and Variables

main( )
input (from keyboard)
integer (return from the function)

int_test( )
value (from main( ) function)
result (value to return)


the Output should be:
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

----------------------------------------------------------------------------------------------------------


Please help me to solve this problem using FUNCTIONS in C programming within 24 hours... thank You very much!!!
Oct 23 '07 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
I bet your teacher didn't set a deadline of 24 hours on you so why do you want
to impose that on us?

kind regards,

Jos
Oct 23 '07 #2

amitpatel66
Expert 100+
P: 2,367
Write this program uding FUNCTIONS

Write a program that accepts any number from the keyboard and tells you whether it is a nonnegative integer. The number should be sent to the function int_test( ), which returns either the integer value, or -1 if the number is negative, or zero if it is nonnegative but not an integer. Inputs should continue until zero is input.

Functions and Variables

main( )
input (from keyboard)
integer (return from the function)

int_test( )
value (from main( ) function)
result (value to return)


the Output should be:
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

---------------------------------------------------------------


Please help me to solve this problem using FUNCTIONS in C programming within 24 hours... thank You very much!!!
Check out the below pseudo code that qould help:

int main()
{
a int;
res int;
cout << "Enter number";
cin >> a;
res = int_test(a);
if(res = -1) then
cout >> "number is negative";
else if (res = 0) then
cout >> "number is zero";
else if (res = 1) then
cout >> "number is not an integer";
else
cout >> "number is" + res;
end if;
return 0;
}

int int_test(b int)
{
res int
if(b < 0) then
res = -1
else if (b = 0) then
res = 0
else if char_at(char(b),'.') > 0 then
res = 1
else
res = b
end if
return res
}

I hope above code/logic would help.
Apologies for any syntax errors!!

Regards,
Amit
Oct 23 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.