#Trying to make the Collatz Conjecture but also with negative numbers (except it's 3n-1 if negative)

10 messages · Page 1 of 1 (latest)

chrome sierraBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

hearty sleet
#
<source>:11:10: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
    if(n = 0){
       ~~^~~
<source>:11:10: note: place parentheses around the assignment to silence this warning
    if(n = 0){
         ^
       (    )
<source>:11:10: note: use '==' to turn this assignment into an equality comparison
    if(n = 0){
         ^
         ==
#

compiler warnings could have caught this one

#

also

        if (n % 2 == 0)
        {
            n = n / 2;
        }
        else
        {
            n = 3 * n + 1;
        }

can be rewritten as

if (n % 2 != 0) {
    n = 3 * n + 1;
}
n /= 2;
#

because 3 * n + 1 for odd numbers will always produce an even number, so you could take two steps at once if you wanted to

deep furnace
#

using the result of an assignment

#

use '==' to turn this assignment into an equality comparison

#

read this

#

its the most clear warnings you will get

chrome sierraBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.