im writing a simple program that turns a decimal to hex. im only posting the piece of code where i have the problems

string hexnumeral (int d) {
       int h,l;
       string e,y,f;
       if (d < 16)
             return hexdigit (d);
       else {
            f = d / 16;
            h = d % 16;
            f += h;
            y = hexdigit (h);}
                if (h == 0) 
                      return f += "0";
                else 
                      return f;
}

when is the number is under 16 everything is good. but if its 16 or over i get "0"
the hexdigit fuction is basically a list of
if h=1
return 1
if h==2
return 2
etc its quite long so i omitted it

jjust to make this clear im having the problem startign with the first else in the code

stringstream is the simplest way to convert an int into hex string

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int n = 255;
    string s;
    stringstream stream;
    stream << hex << n;
    stream >>  s;
    cout << s << "\n";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.