This program is supposed to convert a 5 digit number to hexadecimal.
// newsample.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
//#include "convert2int.h"
using namespace System;
using std::setw;
using std::atoi;
using std::setbase;
using std::dec;
using std::hex;
using std::oct;
using std::showbase;
int fifthdigit(int num)
{
int e=num%10000%1000%100%10;
return e;
}
int fourthdigit(int num)
{
int d=(num/10)%10;
//convert2int(int d);
return d;
}
int thirddigit(int num)
{
int c=(num/100)%10;
return c;
}
int seconddigit(int num)
{
int b=(num/1000)%10;
return b;
}
int firstdigit(int num)
{
int a=(num/10000)%10;
return a;
}
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
int a;
int b;
int c;
int d;
int e;
int num;
std::cout<<showbase<<"Enter a 5-digit #";
std::cin>>num;
std::cout<<hex<<firstdigit<<" "<<seconddigit<<" "<<thirddigit<<" "<<fourthdigit<<" "<<fifthdigit<<" ";
std::cin>>num;
return 0;
}
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
// TODO: reference additional headers your program requires here
the program does not convert the individual digits into hexadecimal
As a concept, that sounds wrong. An individual (decimal) digit will be in the range 0 to 9. If that digit is then converted to hexadecimal, the result will be a digit in the range 0 to 9. (i.e. it will look exactly the same).
What you need to do is to convert the number as a whole into a series of hexadecimal digits. Typically that would involve repeatedly finding the remainder when the number is divided by 16, and translating that remainder into one of the characters 0, 1, 2 ... D, E, F.