#include <iostream>
#include <conio.h>
usingnamespace 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 "<<aux<<"";
cout<<" ";
if(aux%2==0) { cout<<0; array[i] = 0; } // ADD ----------------------------------
elseif(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 "<<base10<<" from base 10 to bese 2 is "; // <<inv<<"."; <-- Not good; ----------------------------------
// ADD ----------------------------------
for (int j = i-1; j >= 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();
}
#include <iomanip> // ADD ----------------------------------
#include <iostream>
#include <conio.h>
usingnamespace 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 ----------------------------------
elseif(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 "<<base10<<" from base 10 to bese 2 is "; // <<inv<<"."; <-- Not good; ----------------------------------
// ADD ----------------------------------
for (int j = i-1; j >= 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.