### Octal number

I need to make this... to input an octal number and it would output the binary like converting the octal number to a binary... thisi s my code so far.. yet it wont run.. please help me in this problem.

#include"stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
void binary(int);

void main(void) {
int number;

cout << "Please enter a octal integer: ";
cin >> number;
if (number < 0)
cout << "That is not a positive integer.\n";
else {
cout << number << " converted to binary is: ";
binary(number);
cout << endl;

}

{
void binary(int number)
{
int remainder;
}
if(number <= 1)
{
cout << number;
return;
}

int remainder;
remainder=number%2;
binary(number >> 1);
cout << remainder;

system("pause>0");
}

what's wrong with my program?? it says.. end of file found before the left brace '{' aside from the curly brackets??
Last edited on
Does this compile?

things to consider 1) main should be int main not void main 2) match the "{" and "}" 3) indent the code well so that you and forum members can read and understand it well 4) post the code in the forum encasing it in the code tag
okay... so i fixed my code...
here'es my new one :

void dec2bin ( int num )
{
int remainder;

if(num <= 1) {
cout << num;
return;
}

remainder = num%2;
dec2bin(num >> 1);
cout << remainder;
}
void dec2oct( int num )
{
int i, n, r, b = 0;
n = num;
i = 0;
while(n != 0 ) {
r = n % 8;
b = b+pow(10.0,i)*r;
n = n/8;
i++;
} // end while
cout << "Octal number is: " << b << endl;
}
void dec2base(int num, int base) {
if (num >= base) { dec2base(num/base, base); }
cout << num % base;
}

when i search all over the net... it always have a "void " function and not "int main" but the only problem here is that... conversion from 'double' to 'int', possible loss of data that's what it says. Please help me run this program.
Last edited on
If its complaining about line `b = b+pow(10.0,i)*r;` then its about the pow function, it returns a double and b is an int.
That is the reason compiler is complaining. If you are not worried about large numbers as input you can typecast the result of pow to int. Otherwise you will have to change b to double.
how can i do that? what do i have to change? can you please show me? :D thankss.
b = b+int(pow(10.0,i))*r;
I already changed it .. and when i run the code it says.. unresolved external symbol _main referenced in function ___tmainCRTStartup
did you remove main from your code? :) second code that you posted is missing main I think
Please use code tags - the <> button on the right.
Does this help?

 http://www.cplusplus.com/forum/general/81758/#msg439040