# help me with C++ programming

Status
Not open for further replies.

#### armess

##### Member level 3
Hai,
can somebody help me with the C++ program of converting a decimal no into its hexadecimal form.
If possible plz send the code.

#### alpk

##### Newbie level 4
Have you tried searching google for your answer, search decimal to hex, and vice versa, you will find many, many answers on there. If you pay me I will write your code.

Maybe this is what you need: https://forums.dreamincode.net/showtopic14696.htm

#### Lucifre

##### Full Member level 2
here is the code:

Code:
#include <iostream>
using namespace std;

int main(){
int userinputdec;
cout << "Please enter a number in decimal: ";
cin >> userinputdec;
cin.ignore();
cout << "The number in hex is: ";
cout << hex << uppercase << userinputdec << endl;
cout << "enter 1 to exit and any other key to continue: " ;
cin >> selection;
cin.ignore();
}
if this is what you're looking for

OOOOPS sorry wrong code
i meant
Code:
int main(){
int userinputdec;
cout << "Please enter a number in decimal: ";
cin >> userinputdec;
cin.ignore();
cout << "The number in hex is: ";
cout << hex << uppercase << userinputdec << endl;
cin.get();
}
sorry bout that

#### shabab

##### Member level 3
YOU CAN MAKE YOUR OWN FUNCTION THERE IS NO STANDARD FUNCTION

#### tjr

##### Member level 3
void findhex(int num)
{
int d,i=0,val;
char hex[6];
while(num)
{
d=num%16;
if(d>=10&&d<=15)
{ val=d-10;
if(val>=0)
hex=65+val;
}
i++;
num=num/16;
}
hex='\0';
strrev(hex);
printf("Hexa num: %s",hex);
}

here findhex() is user defined function
strrev() is std library function defined in "string.h"

Status
Not open for further replies.