My code works fine for c++. You just need to include library stdio.h.
Code:
#include <stdio.h>
#include <iostream>
using namespace std;
void printBin( int var ) {
int i;
for (i=11; i>=0; i--)
printf("%d", (var >> i) & 1);
putchar('\n');
}
int main() {
int n; // number to convert to binary
while (cin >> n) {
if (n > 0) {
cout << n << " (decimal) = ";
printBin(n);
cout << " (binary) in reverse order" << endl;
} else {
cout << "Please enter a number greater than zero." << endl;
}
}
return 0;
}