// This program will hopefully convert decimal numbers to other bases. // Paul Sableman // 1/3/2005 #include using namespace std; int main() { int num, base=2, rem[10], bin, x; char ans; start: x=1; cout << "This program will convert whole numbers to the base of your choice." << endl; here: cout << "Enter the base between 2 and 16 you would like to convert to: "; cin >> base; if(base < 2 || base > 16) { cout << "try again" << endl; goto here; } cout << "Please enter the number you would like converted to base " << base << ": "; cin >> num; while(num != 0) { rem[x] = num%base; num = num/base; x++; } x--; while(x != 0) { if(rem[x] == 10) cout << "A"; if(rem[x] == 11) cout << "B"; if(rem[x] == 12) cout << "C"; if(rem[x] == 13) cout << "D"; if(rem[x] == 14) cout << "E"; if(rem[x] == 15) cout << "F"; if(rem[x] < 10) cout << rem[x]; x--; } cout << endl << "Run again? (y,n) "; cin >> ans; if(ans == 'y' || ans == 'Y') goto start; return 0; }