Base 10 to Base 8 program

Hi everyone. I am trying to create a program to convert numbers into base 8 using a function but it outputs 0 every time. I cannot figure out why. Can someone help me with the code below?


#include <iostream>
#include <cstdlib>
using namespace std;
int convert(int);
int main()
{
int dummy;
int base10;
cout << "Enter your base 10 number" << endl;
cin >> base10;
cout << "Your number " << base10 << " is " << convert(base10) << " in base 8";
cin >> dummy;
return 0;
}
int convert(int a)
{
int base8 = 0;
int number;
number = a;
int remainder=0;
a % 8 == remainder;
base8 = base8 + remainder;
return base8;
a = int(a / 8);
a % 8 == remainder;
base8 = base8 + (remainder * 10);
return base8;
a = int(a / 8);
a % 8 == remainder;
base8 = base8 + (remainder*100);
a = int(a / 8);
return base8;
}
Can you please use the code format tags to format your code. I've taken a look at it and that convert function doesn't make much sense to me.

Can you describe in any way suitable how your convert a base 10 number to base 8. If you can describe it, then we can help you to code it in C++.
Topic archived. No new replies allowed.