Skip to main content
added 87 characters in body
Source Link
Calak
  • 2.4k
  • 11
  • 19

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

Test yourself

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. And 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;`

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';
}

And 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;
  • 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

Test yourself

added 87 characters in body
Source Link
Calak
  • 2.4k
  • 11
  • 19

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. And 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 de /= 8;/= 8;`

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. And about your code:

  • Avoid using namespace std, it's a bad practice
  • Define variables in the closest scope possible.
  • Try naming variable consistently
  • de=de/8; can be simplified to de /= 8;

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. And 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;`
added 168 characters in body
Source Link
Calak
  • 2.4k
  • 11
  • 19

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';
}

AndAt least for the integral part. And about your code:

  • Avoid using namespace std, it's a bad practice
  • Define variables in the closest scope possible.
  • Try naming variable consistently
  • de=de/8; can be simplified to de /= 8;

Just, i don't understand why?

What's wrong with:

#include <iostream>
int main() {
    int input;
    std::cout << "Enter decimal number: ";
    std::cin >> std::dec >> input;
    std::cout << '\n' << std::oct << input << '\n';
}

And about your code:

  • Avoid using namespace std, it's a bad practice
  • de=de/8; can be simplified to de /= 8;

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. And about your code:

  • Avoid using namespace std, it's a bad practice
  • Define variables in the closest scope possible.
  • Try naming variable consistently
  • de=de/8; can be simplified to de /= 8;
Source Link
Calak
  • 2.4k
  • 11
  • 19
Loading