#include "stdafx.h" #include using namespace std; #define BASE 6 #define _DEBUG_ using namespace std; int main() { int inputNum, digit, baseToThePower_i = 1, decimalEquiv = 0; int digitErrorFlag = 0; cout << "Enter an integer number in base " << BASE << ":"; cin >> inputNum; while (inputNum > 0) { digit = inputNum % 10; inputNum /= 10; #ifdef _DEBUG_ cout << digit << " : "; #endif if (digit >= BASE) { cout << "Error! There's an invalid digit " << digit << endl; digitErrorFlag = 1; break; } #ifdef _DEBUG_ cout << " " << BASE << "^i = " << baseToThePower_i; #endif int ithTerm = baseToThePower_i * digit; #ifdef _DEBUG_ cout << " ith term = " << ithTerm << endl; #endif baseToThePower_i *= BASE; decimalEquiv += ithTerm; } if (digitErrorFlag == 0) cout << "The decimal equivalent is : " << decimalEquiv << endl; return 0; }