446,260 Members | 1,305 Online
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

# Stuck on this online lab problem.

 P: 64 Here it is the question. Write the definition of a function isSenior , which receives an integer parameter and returns true if the parameter's value is greater or equal to 65, and false otherwise. So if the parameter's value is 7 or 64 or 12 the function returns false. But if the parameter's value is 69 or 83 or 65 the function returns true. This is two of the code of many I tried... Expand|Select|Wrap|Line Numbers   int isSenior(int a) { int true; int false; a = 69; if( a >=65) return true; else  if( a<65) return false;   And Expand|Select|Wrap|Line Numbers int isSenior(int a) { int true; int false; if( a >=65) return true; else  if( a<65) return false;   Without a=69 this time I have no clue what seems to be the problem the error message I get is Suggestion: You are not returning the correct value. Revise your code. I returned false or true and I don't see what the problem is. Thanks in advance for any help. Feb 21 '07 #1
4 Replies

 Expert 100+ P: 1,510 you have defined the two int variables true and false Expand|Select|Wrap|Line Numbers int isSenior(int a) { int true; int false;   but not initialised them - local variables are not initialised and their value is whatever happens to be in memory Feb 21 '07 #2

 P: 96 Horace1 is correct! Both true and false variable contains garbage values.... And therr is no error..in the above code.... please post your whole code... Feb 21 '07 #3

 Expert 2.5K+ P: 3,652 Actually, there is an error. The lab question asks you to return a true or a false - this suggests a bool returning function. You, however, wrote the function to return an int. In the function, the "return true" and "return false" statements are trying to return bool values, but the function wants to return an int value. Feb 21 '07 #4

 P: 96 If you are suppsoe to return 0(False) or 1(True) intialise the true and false value int true=1; int false=0; Feb 21 '07 #5