Solved

Solved
Last edited on
Try to firstly describe or write down the mathematical process of converting a number from base 10 to base 2. Compare it with your code.
You could consider this function to help you.

 ``1234567891011`` ``````void Convert_To_Base_2(int num) { int Array[100]; int i = 0; while(num != 0) { Array[i] = (num % 2); num /= 2; i++; } }``````
Last edited on
I didn't because If you know c++/c/c# you have to know what that means and it is.
Here is the full program for that:

 ``12345678910111213141516171819202122232425262728293031323334`` ``````#include using namespace std; void Convert_From_Base_10_To_Base_2(int num); int main() { int number; cin >> number; Convert_From_Base_10_To_Base_2(number); system("pause"); return 0; } void Convert_From_Base_10_To_Base_2(int num) { int Array[100]; int i = 0; while(num != 0) { Array[i] = (num % 2); num /= 2; i++; } for(int j = i-1; j >= 0; j--) { cout << Array[j]; } cout << endl; }``````
I compared it and it's fine.
P.S. I'm novice.
I know it's fine. I wrote it right now. So, I guess you an close the topic. Unless you want more explanations.

I hope I was helpful,
~ Raul ~
Well, if you need further help, you can always PM me. :)
I didn't asked for another code. I need help how to solve mine.
Last edited on
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445`` ``````#include #include using namespace std; int main(){ int base10, base2=0, aux, inv=0; cout<<"\n\n\n This program transfers a number from base 10 to base 2."; cout<<"\n\n Type the number, from base 10: "; cin>>base10; aux=base10; cout<<"\n Graphical scheme of the calculation..."; // write this in your code int array[100], i = 0; // ADD ---------------------------------- while(aux>0){ cout<<"\n "<=0){ //He's from tale to head. inv=inv+base2%10; base2=base2/10; } */ cout<< endl << "The number "<= 0; j--) cout << array[j]; cout << "."; // --------------------------------------- cout<<"\n\n All rights reserved.\n Isengardium Company...\n Version 1.0\n Press any key to continue..."; getch(); }``````
That's what you need to modify in order to get your code working. I would recommend using the once I gave you, but if you really need this one, okay.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546`` ``````#include // ADD ---------------------------------- #include #include using namespace std; int main(){ int base10, base2=0, aux, inv=0; cout<<"\n\n\n This program transfers a number from base 10 to base 2."; cout<<"\n\n Type the number, from base 10: "; cin>>base10; aux=base10; cout<<"\n Graphical scheme of the calculation..."; // write this in your code int array[100], i = 0; // ADD ---------------------------------- while(aux>0){ cout<<"\n " << setw(6) << aux<<""; // MODIFY THIS ---------------------------------- cout<<" "; if(aux%2==0) { cout<<0; array[i] = 0; } // ADD ---------------------------------- else if(aux%2==1) { cout<<1; array[i] = 1; } // ADD ---------------------------------- base2=base2*10+aux%2; aux=aux/2; i++; // ADD ---------------------------------- } cout<<"\n 0"; /* ---------------------------------- delete while(base2>=0){ //He's from tale to head. inv=inv+base2%10; base2=base2/10; } */ cout<< endl << "The number "<= 0; j--) cout << array[j]; cout << "."; // --------------------------------------- cout<<"\n\n All rights reserved.\n Isengardium Company...\n Version 1.0\n Press any key to continue..."; getch(); }``````

That's it.

Including <iomanip> and using the setw(n) function allows you to set the width of the space where the letters are printed, which alligns them as you wished.

~ Raul ~
Last edited on
Topic archived. No new replies allowed.