Hey guys, I have to write a simple program that can convert decimal to binary but I can only use only nested if else statements.I just need to simply how to set it up and I can go from there. I cannot use loops, void, and stack. Just nested if else. This what I have so far!
Thank you sir! I was trying to use the quotient remainder method and it wasn't really working. Thank you for showing me such a easy way to figure it out.
#include <iostream>
int main()
{
unsignedint number ;
std::cout << "enter a non-negative number less than 256: " ;
std::cin >> number ;
if( number > 255 )
{
std::cerr << "error: out of range\n" ;
return 1 ;
}
std::cout << number / 128 ;
number %= 128 ;
std::cout << number / 64 ;
number %= 64 ;
std::cout << number / 32 ;
number %= 32 ;
std::cout << number / 16 ;
number %= 16 ;
std::cout << number / 8 ;
number %= 8 ;
std::cout << number / 4 ;
number %= 4 ;
std::cout << number / 2 ;
number %= 2 ;
std::cout << number << '\n' ;
}