By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
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
  1.  
  2. int isSenior(int a)
  3. {
  4. int true;
  5. int false;
  6. a = 69;
  7. if( a >=65)
  8. return true;
  9. else 
  10. if( a<65)
  11. return false;
  12.  
And

Expand|Select|Wrap|Line Numbers
  1. int isSenior(int a)
  2. {
  3. int true;
  4. int false;
  5. if( a >=65)
  6. return true;
  7. else 
  8. if( a<65)
  9. return false;
  10.  
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
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 1,510
you have defined the two int variables true and false
Expand|Select|Wrap|Line Numbers
  1. int isSenior(int a)
  2. {
  3. int true;
  4. int false;
  5.  
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

Ganon11
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

Post your reply

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