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

evaluates to true

P: 5
how do I write this out? If I type the word "true" it keeps rejecting it.... ??
Once again, this is intro level so it should be very easy



Write an expression that evaluates to true if and only if the value of the boolean variable workedOvertime is true.
Sep 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: 61
Let us suppose that 1 is true and 0 is false and accordingly you change the status of a variable and check for true or false.
Sep 19 '06 #2

100+
P: 293
D_C
That is a bidirectional implication. Suppose our conditional statement is C(workedOvertime).

When workedOvertime is true, C(workedOvertime) is true. Also, the contrapositive is true. When C(workedOvertime) is false, workedOvertime is false. True and false are the only two possible values, so for all cases C(workedOvertime) is equivalent to workedOvertime.

It's like saying write a function f(x) such that it's output is equivalent to it's input. In that case, f(x) = x.
Sep 19 '06 #3

Banfa
Expert Mod 5K+
P: 8,916
If I type the word "true" it keeps rejecting it.... ??
You mean you get compiler errors?

There is no keyword "true" (or "false") in a lot of C compilers (although I believe it was added to the standard in C99 many compilers still only support C89).

In C the terms true and false are normally appilied to integer expressions (having type char, short, int, long). In this instance a value of 0 is false and any other value is true

e.g. for a char variable

0 = false
1 - 255 = true

Logical expressions (== <= > etc) return 0 or 1. Many (most even) developments end up defining a boolean type, this is normally either an enum or a typedefed integer with #defined true and false values

Expand|Select|Wrap|Line Numbers
  1. typedef char boolean;
  2. #define FALSE  0
  3. #define TRUE   1
  4.  
  5. typedef enum tag_bool {
  6.   false = 0,
  7.   true  = 1
  8. } bool;
  9.  

Whether an expression is treated as a boolean expression or not depends entirely on the context it is used in.



in C99 and C++ there is a bool type defined in the languagewith takes values true and false. In this case bool, true amd false are keywords of the language.
Sep 20 '06 #4

Post your reply

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