Hi,
I'm trying to write a console app that will take in a base 10 number and output that number in binary form. I created a character array for the binary number and a couple of for loops (one to mod the number and divide. One to print the contents of the array.) but, I must have the syntax of something incorrect. I have looked at the code for a couple hours though and cannot figure out the issue. It seems to me when I run the app like the for loops are not even running. Anyways tia for any help.
Code:#include <iostream> #include <stdlib.h> using namespace std; int main(void) { int num = 0; int i = 0; //array to store the binary digits. all values are initialized to 0. int binary[8] = {0}; cout << "Please enter a base10 number between 0 and 255:" << endl; cin >> num; //loop from 7 to 0 modding the number by 2 and then dividing it in half. for (i = 7; i < 0; i--) { binary[i] = (num % 2); num = num / 2; } cout << "Your number is:" << endl; //loop through the binary array printing each digit. for (i = 0; i > 7; i++) { cout << binary[i]; } cout << endl; return 0; }