I want to use a while loop to convert decimal to binary, I have it almost I'm just not sure how to get the rest. Right now it is printing the last two digits of each binary number but not the first to (i.e. 10 = 1010, but is just printing 10).
I'm think I need another loop to keep returning the sum and remainder but I can figure it out. I tried asking my teacher, but he laughed and said quote; 'I'm not helping you, no one will help you when you get a job.'
First off, this is an intro course, I have no idea how to do anything.
Second, I'm going to school to learn how to do it so I can figure problems like this out on my own at a job.
Third, Where the fuck am I working that I wouldn't have anyone else in the department to ask. - sorry needed to blow off some steam.
(The commented out portion is me trying to figure out how to print the first two digits, but failing).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int low;
int high;
int a;
cout << "Enter the low number: ";
cin >> low;
cout << "Enter the high number: ";
cin >> high;
int rem, con, aaa, bbb, ccc;
int sum, dec;
dec = low;
while (dec <= high)
{
sum = dec % 2;
rem = dec / 2;
con = rem % 2;
cout << con << sum << endl;
dec++;
}
/*aaa = sum % 2;
bbb = sum / 2;
ccc = bbb % 3;
cout << bbb << aaa << con << sum << endl;
cout << con << endl;
cout << sum;
aaa = sum % 2;
bbb = sum / 2;
ccc = bbb % 2;*/
return 0;
}
|