There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

GoosLife ,

Sorry, let me try again. Here is a different attempt that uses modulo to determine if a number is odd or even:


<span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="font-weight:bold;color:#a71d5d;">#include 
</span><span style="color:#323232;">
</span><span style="font-weight:bold;color:#a71d5d;">template 
</span><span style="font-weight:bold;color:#a71d5d;">bool </span><span style="color:#323232;">isEven(</span><span style="font-weight:bold;color:#a71d5d;">const</span><span style="color:#323232;"> T</span><span style="font-weight:bold;color:#a71d5d;">&</span><span style="color:#323232;">amp; number) {
</span><span style="color:#323232;">    std::vector digits;
</span><span style="color:#323232;">    std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
</span><span style="color:#323232;">    std::uniform_int_distribution distribution(</span><span style="color:#0086b3;">1</span><span style="color:#323232;">, </span><span style="color:#0086b3;">9</span><span style="color:#323232;">);
</span><span style="color:#323232;">
</span><span style="color:#323232;">    std::string numberStr </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">std::to_string(number);
</span><span style="color:#323232;">
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">for </span><span style="color:#323232;">(</span><span style="font-weight:bold;color:#a71d5d;">char</span><span style="color:#323232;"> digit </span><span style="font-weight:bold;color:#a71d5d;">:</span><span style="color:#323232;"> numberStr) {
</span><span style="color:#323232;">        digits.push_back(distribution(generator));
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">int</span><span style="color:#323232;"> sum </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">std::accumulate(digits.begin(), digits.end(), </span><span style="color:#0086b3;">0</span><span style="color:#323232;">);
</span><span style="color:#323232;">
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#a71d5d;">return</span><span style="color:#323232;"> sum </span><span style="font-weight:bold;color:#a71d5d;">% </span><span style="color:#0086b3;">2 </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">0</span><span style="color:#323232;">;
</span><span style="color:#323232;">}
</span>
  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines