954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Logic Programming Problem

Hello guys,

I've recently come across this problem and have spent quite a bit of time trying to comprehend what the question is actually telling me to do :S

.If a, b, c are bool-variables, a is true, but b and c are false, write an expression that computes the logical value of ( a && b ) || c, assign it to a bool d, and
depending on the result print “d is true” or “d is false”. What does “( a && b ) ||
c” mean

If anyone can help me out then it would be much appreciated :). Sorry that I have not put any code examples, I keep deleting them because I'm not sure if I have to assign a variable a value and then create a function to see if can work it out or something completely different... I'm just lost :/

Falcon25
Light Poster
35 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

&& is the and operator; the way it works is the value it returns is true when both sides of it are true, and only when both sides are true, any other time it returns false.

|| is the or operator; I forget how it returns until I'm actually using it for some reason, but it's about like saying if (x is > y or x is > 15) doSomething();.

! is the not operator; this basically returns the opposite of the boolean value you assign it to. When used in conditionals if (x != 10) this basically saying that if x is not equal to 10 (any other value than 10) to execute the code in the if block.

So basically if I remember correctly the or operator returns true only when both sides are false. So when a is true, b is false, and c is false; the statement (a && b) || c should return false.

The if () conditional only checks for boolean values, even when using integers or strings it returns a true or false value to the if. When the value is true (condition met) then it executes the code block below it. If it returns false (condition not met) it skips the following block of code and checks for an else if or else block.

That should sum it up quite decently, if you need anything else just let me know. Please just note, I'm not the best at explaining my knowledge (hence the reason I don't give too many lessons) so it may be off a little.

lxXTaCoXxl
Posting Whiz
300 posts since Mar 2011
Reputation Points: 22
Solved Threads: 18
 

hey dude

&&-means logical AND operation
||-means logical OR operation

give problem is
a=true;
b=false;
c=false
then
d=( a && b ) || c
//a && b-means (true && false)
//&&-return true when both input are true here one is true (a) another
//one is false(b) this will return false
//in next step it calculate false || C
// ||-return true when any one of the input true here both are false (a&&b)
// and c so result false will assigned to d
hence result d is false

mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: 0
Solved Threads: 7
 

hey dude

&&-means logical AND operation ||-means logical OR operation

give problem is a=true; b=false; c=false then d=( a && b ) || c //a && b-means (true && false) //&&-return true when both input are true here one is true (a) another //one is false(b) this will return false //in next step it calculate false || C // ||-return true when any one of the input true here both are false (a&&b) // and c so result false will assigned to d hence result d is false

I believe that was my response just in shorter and more confusing words? O_o

lxXTaCoXxl
Posting Whiz
300 posts since Mar 2011
Reputation Points: 22
Solved Threads: 18
 

Thanks for all your help guys. Going to mark this one as solved.

Falcon25
Light Poster
35 posts since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You