answersLogoWhite

0


Best Answer

#include
#include

using std::cin;
using std::cout;
using std::endl;
using std::tolower;

inline void decToHexOct(unsigned int number, char base);

int main()
{
cout << endl << "Enter a number: ";
unsigned int number = 0;
cin >> number;

cout << endl << "Choose base:"
<< endl << "h//H for Hex"
<< endl << "o//O for Octal"
<< endl;
char base = 'h';
cin >> base;

decToHexOct(number, base);

system("PAUSE");
return 0;
}

inline void decToHexOct(unsigned int number, char base)
{
if (tolower(base) == 'h')
{
cout << endl << "Number in hex is: " << std::hex << std::showbase << number
<< endl;
}
else if (tolower(base) == 'o')
{
cout << endl << "Number in octal is: " << std::oct << std::showbase << number
<< endl;
}
else
{
cout << endl << "Wrong base...";
system("PAUSE");
exit(1);
}
}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a C program to convert decimal number into binary hex and octal A function should be used with two integer parameteres first for the number to be converted and second for the base help urgent?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you convert 3.68 into a decimal?

3.68 is already a decimal and does not need to be converted.


Convert 18 to a decimal?

18 (eighteen) is an integer and does not need to be "converted to a decimal"1/8 (one eighth) is a fraction and can be converted into a decimal: 0.125


How convert 123789 into binary?

Converted from decimal to binary, 123789 is equal to 11110001110001101.


What is 12 percent converted to a decimal?

To convert a percentage to a decimal, divide by 100: 12 % = 12 &divide; 100 = 0.12


How do you convert octal to binary with 2 decimal nos?

The conversion of octal number to binary can be obtained by using two methods. First, it can be converted into decimal and then obtained decimal is converted into binary. In the second method


What is the answer to 0.02 converted into a percent?

to convert a decimal to percent, multiply by 100. 0.02 = 2%


How do you convert fraction to decimal and vise versa?

Decimals can only be converted into fractions if they are rational numbers


Convert 615 to a decimal?

615 is a whole number and as such has no need to be converted to a decimal. It could be represented as 615. but it ends in a five and so the terminal decimal is meaningless.


Convert 0.02687 into a whole number?

A whole number is a number that is not a decimal or fraction. Since 0.02687 is a decimal, it cannot be converted into a whole number.


How do you convert 38 to decimal?

38 is an integer, it does not need to be converted. 3/8 is a fraction, it is equal to 0.375


Do equivalent fractions convert to the same decimal?

NoImproved Answer:-Yes equivalent fractions can be converted into identical decimals.


What are the numbers in the smallest group of repeating digits when 4111 is converted to a nonterminating decimal?

4111 is an integer and so there is no sensible way to convert it into a repeating decimal.