473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Stuck on this online lab problem.

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
4 3890
horace1
1,510 Expert 1GB
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
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
3,652 Expert 2GB
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
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

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

Similar topics

9
by: Thomas Baier | last post by:
Hi there, I've got a class with an method that creates a temporary object of its own class and then copies this objekt into the this pointer like class myclass { protected: //... public:...
0
by: Lior Bobrov | last post by:
Hello . I now have Visual Studio 2005 Common Technology Preview (CTP) February 2005 with no MSDN . I try to use the MSDN Online from within the IDE , as follows : In the IDE , I click...
8
by: Daniel Billingsley | last post by:
I've got to believe this is a fairly common / classic problem, and I think I've even read an example somewhere in my education thus far, but I sure can't remember it. Suppose I want to store a...
2
by: Jason Huang | last post by:
Hi, I've been thinking how to have our C#.Net application go production, we use Windows Form in our AP, and we have about 150 PC and clients. Thanks for help. Jason
1
by: Shapper | last post by:
Hello, I am accessing a value in a XML value: news.Load(Server.MapPath("xml/ news.rss")) newslabel.Text = CType(news.SelectSingleNode("rss version=&quot;2.0 &quot;/channel/title").InnerText, String) ...
0
by: bootleggersplayr | last post by:
anyone who can write some scripts for me for this online game would be an lifesaver pm me!
7
by: michigaki | last post by:
hello, we are having problems in compiling a 'slightly' altered x264. We are always receiving a 'helloWorld' undeclared (first use this function) error. We may be commiting a very simple error but...
8
by: Blast | last post by:
I need help modeling schema for a particular issue that i've never run across before. And for the life of me, I cannot figure out how to model it - at least in a way that feels correct. Please let...
1
by: JB | last post by:
Does anyone know why this code works in example A but not in example B ? Is this a problem with special characters within the data values? A) Set xmlNodeList =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.