Decimal

Program that would output the decimal number of the octal number you have entered. This code is working but it is not correct :/


int main()
{

int input;
cout << "Enter an octal number:";
cin >> input;
cout << "\nDecimal number = " <<dec<< input << "\n";

system("pause>0");
return 0;
}
The default input/output mode is decimal. cin >> input; inputs a number in decimal. You have to tell it to use octal.
It still dont display the decimal number of the octal number that i have put..
What is your current code?
here...
int main()
{
int octal;
int num;
cout << "Enter an octal number:";
cin >> octal;
cout << "\nDecimal number ="<<num<<octal << "\n";
cin >> num;
system("pause>0");
return 0;
}

I tried to delete 'cin >> num;' but it still wont work.
Last edited on
cin >> octal;
Just because the variable is named octal does not mean it actually takes input as octal and converts it to binary representation in memory. This statement still takes input in decimal format.
Oh? so... what should i put insted of cin >> octal?
http://www.cplusplus.com/reference/iostream/manipulators/oct/
For example,
1
2
std::cin >> std::oct >> MyIntVariable;
std::cout << MyIntVariable; //std::dec is default, you don't need to specify it 
Topic archived. No new replies allowed.