nave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agoI wishi.imgur.comimagemessage-square189fedilinkarrow-up1928arrow-down117
arrow-up1911arrow-down1imageI wishi.imgur.comnave@lemmy.zip to Lemmy Shitpost@lemmy.worldEnglish · 1 year agomessage-square189fedilink
minus-squareGoosLife@lemmy.worldlinkfedilinkarrow-up7·1 year agoSorry, let me try again. Here is a different attempt that uses modulo to determine if a number is odd or even: #include #include #include #include #include #include #include #include #include #include template bool isEven(const T& number) { std::vector digits; std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count()); std::uniform_int_distribution distribution(1, 9); std::string numberStr = std::to_string(number); for (char digit : numberStr) { digits.push_back(distribution(generator)); } int sum = std::accumulate(digits.begin(), digits.end(), 0); return sum % 2 == 0; }
minus-squarenogrub@lemmy.worldlinkfedilinkarrow-up2·1 year agoi think you forgot an include there also a goto statement would work better
Sorry, let me try again. Here is a different attempt that uses modulo to determine if a number is odd or even:
i think you forgot an include there also a goto statement would work better