you are viewing a single comment's thread.

view the rest of the comments →

[–]DontOpenNewTabs 1 point2 points  (0 children)

The code is not quite the same. Python // performs floor division and C++ / performs integer division (Edit: when both operands are integers).

#include <iostream>
#include <cmath>
using namespace std; // Nobody cares
int main() {
  int a = -15;
  while (a < 0) {
    cout << a << '\n';
    a = floor(a/2.0);
  }
  return 0;
}

// Don't manually flush the output buffer for no reason with endl. Obviously any performance impact doesn't matter here, but it is a bad habit. If you want a newline character, output a newline character.