English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i have an assignment in my computer science class. i have to write a program that takes in the expiration date of a food product, the current date, and tells whether or not the product is expired or not.

i have to use 3 bool functions ( 'isvalid' returns if a date is valid, has parameters that represent one date) ( 'thesame' tells if the two dates are the same, has parameters that represent two dates) ( 'earlier' returns true if the first date is earlier than the second date and false otherwise, has parameters that represent two dates) and a void function ( 'output_date' which takes parameters that represent one date and outputs it to the screen)
here is the output:
Enter expiration date in the form mm/dd/yyyy: 2/1/2017
Enter today's date in the form mm/dd/yyyy: 2/15/2013
The expiration date you entered is 2/01/2017
The current date you entered is 2/15/2013
The expiration date is later than today, this food is ok!

i just need help writing a bool function. idk how to make one

2007-03-19 10:17:24 · 4 answers · asked by 63godtoh 3 in Computers & Internet Programming & Design

this goes out to Rex M who left the first comment.

could you be a little more vague? i said i do not know how to write them, thats not even showing me how to write it, its just giving a general idea, i said i need help because i dont have the slightest clue how to write a bool function

would someone please give me like a full example of a bool function, and before you answer, look at what Rex M put and hear me when i say 'that was way to vague of an answer for me to understand'

2007-03-19 10:28:17 · update #1

ok just so people dont keep saying "rex m's' answer is detailed, what are you talkin about!"

before his answer was in two lines and it didnt help me because it was very vague, i dont care what anyone says. coming from someone who says they dont know much about it i can tell you that it was very vague.

but then after i said that, he went back and added more detail into his answer, but stupid yahoo answers wont let you know that, so it looks like he put all that stuff in the first time when he didnt

...also i forgot to mention im working in C++ and thats what my teacher wants us to use so this whole page is completely useless to me now

2007-03-20 09:29:08 · update #2

4 answers

try this

http://code.google.com/

2007-03-19 10:29:44 · answer #1 · answered by Nitesh G 2 · 0 1

With all due respect to the question poster, if you don't understand our explanations, it may be a sign that you need to read your course material. If you ask about bool functions, but don't understand us when we talk about functions in general, and return types for functions, we can only ask what exactly do you know?

Also, Rex was is no way vague. In fact, the opposite as seen by his long and detailed answer. It is you in fact, who is terribly vague. You haven't even specified your programming language of choice (talk about vague). You refuse to specify what you don't understand about a bool function. For that matter, what do you mean by a bool function. Defining a function with a bool return type? Using a function with a bool return type?

Please take a good look at your assignment. It's not so much that you have to write a function that returns a boolean. Instead, you are given functions and must use them to determine if an expiration date is past the current date. This is really just a series of function calls.

Thus, you should read up on the section for functions, passing arguments to functions, and calling functions. You could write it all in one line of code, but I suspect you will want to have temporary variables. Hopefully, you know how to declare and define a variable, and you will have to make sure it is the correct return type of the function.

If you don't understand the previous paragraph, please read your course material. Or ask a more specific question we can help you on.

2007-03-19 18:05:35 · answer #2 · answered by csanon 6 · 1 0

public bool MyFunctionName(DateTime expiry)
{
//logic here
return boolean;
}

OK, let's try again here. A bool function is a function (also known as a method) that returns a boolean value. Using c#, we construct a function/method like so:

accessor returntype functionname(parameters)
{
programming logic
return value
}

Parameters are defined as DataType parameterName, and each parameter is separated by a comma.

Now, for simplicity's sake, we will use the public accessor. We want to return a bool value. We will call the function/method MyFunctionName, and you say it needs to accept the expiration date of a food product, and the current date. Since it is pointless to have a function accept the current date (it can just look it up by itself), we will have it just accept the expiration date:

public bool MyFunctionName(DateTime expiry)
{

}

Now, lets try writing the boolean function "thesame":

public bool TheSame(DateTime date1, DateTime date2)
{
if(date1 == date2)
{
return true;
}
else
{
return false;
}
}

This can be simplified by writing:

public bool TheSame(DateTime date1, DateTime date2)
{
return date1==date2;
}

date1==date2 is an expression; think of it as declaring to the computer that the value of date1 equals the value of date2. If that statement ends up being true, the computer will return true. If it's false, the computer will return false.

I hope that gives you enough information to write the other methods in your project. I also hope you can be a little more appreciative in the future when strangers offer to help you do your homework for free.

2007-03-19 17:22:48 · answer #3 · answered by Rex M 6 · 2 0

I guess Rex M's answer was detailed and perfect.

2007-03-20 15:43:21 · answer #4 · answered by Smutty 6 · 0 0

fedest.com, questions and answers