``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112`` ``````#include #include #include // Positional value unsigned short store = 0; // This is to hold how many positions we need to check unsigned short highest; unsigned short base; unsigned long number; bool first; // Return a number input int cin_int(std::string msg); int main() { std::cout << "Decimal to Radix converter\n\ Instead of representing values that are above 9 as letters (e.g., in hex) a value is shown in between pipes.\ (Converting 255 to hex would not output 'FF', it would output '15|15')\n(Ctrl+C to exit)\n"; while (true) { highest = 1; base = cin_int("Enter an integer radix:\n"); number = cin_int("Enter an integer to convert:\n"); std::cout << "Result of conversion: \n"; // Figure out the highest position that the number could calculate to for (unsigned short i = 1; i < number; i *= base) { highest *= base; } first = true; for (unsigned short i = highest; i > 0; i /= base) { // Prevent a leading 0 if (first) { first = false; continue; } store = 0; for (unsigned short d = 1; d < base; d++) { if (number / i % base == d) { store = d; } } std::cout << store; // Output a pipe between positions if (i >= base) { std::cout << '|'; } } std::cout << std::endl; } return 0; } int cin_int(std::string msg) { int num; while (true) { std::cout << msg; while (!(std::cin >> num)) { std::cout << msg; std::cin.clear(); std::cin.ignore(std::numeric_limits::max(),'\n'); } if (num > 1) break; else { std::cout << "Input must be above 1!\n"; } } return num; }``````