Oct 14, 2012 at 1:02am UTC
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;
}
Oct 14, 2012 at 1:23am UTC
The default input/output mode is decimal. cin >> input;
inputs a number in decimal. You have to tell it to use octal.
Oct 14, 2012 at 1:33am UTC
It still dont display the decimal number of the octal number that i have put..
Oct 14, 2012 at 1:41am UTC
What is your current code?
Oct 14, 2012 at 1:47am UTC
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 Oct 14, 2012 at 1:47am UTC
Oct 14, 2012 at 1:49am UTC
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.
Oct 14, 2012 at 1:56am UTC
Oh? so... what should i put insted of cin >> octal?