468,513 Members | 1,870 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

evaluates to true

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
3 23514
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
D_C
293 100+
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
9,056 Expert Mod 8TB
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.

Similar topics

3 posts views Thread by Eric Linders | last post: by
1 post views Thread by mg | last post: by
1 post views Thread by Erik Tamminga | last post: by
reply views Thread by mg | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.