//Tyler Arthur // Program 8 Assignment 4 // CS 201 #include #include using namespace std; bool isDigit(char c); int digit2int(char c); bool isValid(int d2, int d1, int d0, int base); int base10(int d2, int d1, int d0, int base); int main() { int base; char a; char b; char c; int d2; int d1; int d0; cout << "Enter the first digit: " << endl; cin >> a; cout << "Enter the second digit: " << endl; cin >> b; cout << "Enter the third digit: " << endl; cin >> c; cout << "Enter the base: "; cin >> base; if (isDigit(a)) { cout << a << " " << "is a valid digit" << endl; if (isDigit(b)) { cout << b << " " << "is a valid digit" << endl; if (isDigit(c)) { cout << c << " " << "is a valid digit" << endl; if(base <= 10 && base >=2) { cout << base << "is a valid base" << endl; d2 = digit2int(a); d1 = digit2int(b); d0 = digit2int(c); if(isValid(d2, d1, d0, base)) { cout << d2 << d1 << d0 << " " << "in base" << base << "is equal to" << " " << base10(d2, d1, d0, base) << " " << "in base 10." << endl; } else { cout << base << " " << "is not a valid base" << endl; } } else { cout << d2 << d1 << d0 << " " << "in the given base is not valid" <= '0' && c <= '9') { return true; } else { return false; } } int digit2int(char c) { return (c - '0'); } bool isValid(int d2, int d1, int d0, int base) { if(base < d2 || base < d1 || base < d0) { return true; } else { return false; } } int base10(int d2, int d1, int d0, int base) { return (d2 * base * base + d1 * base + d0); }