Conversia unui numar din baza 10 in baza 16

#include <iostream>

int main()
{
    char hexa[10];
    int a = 0, i = 0;
    std::cin >> a;
    while (a > 0) {

        switch (a % 16) {
        case 0:
            hexa[i] = '0';
            break;
        case 1:
            hexa[i] = '1';
            break;
        case 2:
            hexa[i] = '2';
            break;
        case 3:
            hexa[i] = '3';
            break;
        case 4:
            hexa[i] = '4';
            break;
        case 5:
            hexa[i] = '5';
            break;
        case 6:
            hexa[i] = '6';
            break;
        case 7:
            hexa[i] = '7';
            break;
        case 8:
            hexa[i] = '8';
            break;
        case 9:
            hexa[i] = '9';
            break;

        case 10:
            hexa[i] = 'a';
            break;
        case 11:
            hexa[i] = 'b';
            break;
        case 12:
            hexa[i] = 'c';
            break;
        case 13:
            hexa[i] = 'd';
            break;
        case 14:
            hexa[i] = 'e';
            break;
        case 15:
            hexa[i] = 'f';
            break;

        }
        i++;
        a = a / 16;
    }
    for (int j = i-1; j >=0; j--) {
        std::cout << hexa[j];
    }
}