Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to know if you could solve (40000-4x1064/4) && (x|| y && z || c). It should be a yes no answer and I really need to figure out what the answer is as soon as possible.

What I have tried:

I actually don't even know where to start.
Posted
Updated 16-Nov-17 5:39am
v2
Comments
ZurdoDev 16-Nov-17 11:15am    
Yes. Now what exactly is your question?
Member 13525148 16-Nov-17 11:42am    
What would be the solution of the problem. I need to know if the answer is yes or no.
Richard MacCutchan 16-Nov-17 11:18am    
It is just a simple mathematical formula. Take it one step at a time and you will find it quite easy.

1 solution

See C++ Operator Precedence - cppreference.com[^].

Then break the expression down step by step according to the precedence and replacing fixed expressions (those that did not contain variables). It is often also helpful to insert parentheses first according to the precedence.
If you have for example
C++
a || b && c
it will be
C++
a || (b && c)

Because your question looks like homework, I will not give you a final answer. Even if it is not homework, you should do it yourself to understand how it works.
 
Share this answer
 
Comments
Member 13525148 16-Nov-17 11:36am    
It isn't homework. I was given it as a riddle to solve. Thank you for your advice. I have actually never done any type of c plus plus programming before, or any programming for that matter.
Could you explain to me how to solve it.
Jochen Arndt 16-Nov-17 14:23pm    
You don't have to know C/C++ to solve this if you know what the used operators are doing (logical OR and AND: TRUE/yes if one of the operands is TRUE resp. TRUE if both operands are TRUE where TRUE means that an operand/result is not zero) and in which order they are processed (the precendence).

Just try my advice to set parentheses first and then simplify the expression using old style pencil and sheet of paper.

You might then note that the result of the expression depends on the values of the used variables if the first term is not zero (BTW: you have changed that term in the subject after I have posted my solution: the ^ operator was initially not there).

The obvious answer to the vague question is:
Yes it can be solved providing that the variables are numeric types (can be used for boolean expressions) or are C++ classes that have an implicit numeric return type.
Member 13525148 17-Nov-17 13:32pm    
Thank you I ended up figuring it out and the person said I had the right answer.
Member 13525148 17-Nov-17 15:08pm    
The answer is not zero, correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900