from decimal to hexadecimal using random access

PHOTO EMBED

Tue Dec 14 2021 07:55:04 GMT+0000 (Coordinated Universal Time)

Saved by @abzal_nurgazy #c++

#include <iostream>
#include <string>
using namespace std;
using std::string;
const string hexdigits = "0123456789ABCDEF"; // possible hex digits


int main()
{
	
	cout << "Enter a series of numbers between 0 and 15"
		<< " separated by spaces. Hit ENTER when finished: "
		<< endl;
	string result = ""; // will hold the resulting hexify’d string
	unsigned int n; // hold numbers from the input
	

	while (cin >> n )
	{
		if (n < 16) // ignore invalid input
			result += hexdigits[n]; // fetch the indicated hex digit
		else if (n == 17)
			break;
	}

	cout << "Your hex number is: " << result << endl;

	return 0;
}

content_copyCOPY