Just, i don't understand why?
What's wrong with (for integer):
#include <iostream>
int main() {
int input;
std::cout << "Enter decimal number: ";
std::cin >> std::dec >> input;
std::cout << '\n' << std::oct << input << '\n';
}
At least for the integral part. AndAnd about your code:
- Avoid
using namespace std
, it's a bad practice - Just
main()
isn't a valid prototype for the entry point, at least use `int main() - Define variables in the closest scope possible.
- Try naming variable consistently
de=de/8;
can be simplified to `de /= 8;`de /= 8;
- floating point conversion is a bit more tricky than just doing what you do
Edit: After testing it (and correcting main()
and) : Your code just doesn't work, even for an integer value
Enter decimal no :: (0)10 = (32767.)8
Enter decimal no :: (8)10 = (32776.)8
Enter decimal no :: (10)10 = (32779.)8