// 36base.cc
/*
LGPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include
using std::cout;
using std::cin;
using std::endl;
int base = 36;
void printBase(int i)
{
if(i > (base - 1))
{
// beautiful recursion ;)
printBase(i / base);
i %= base;
}
if(i < 10) // If it's 0-9 just print it!
cout << i;
else
{
//Since 'A' = 65 then 10 + 55 = 'A'
i += 55;
cout << (char)i;
}
}
int main()
{
//Interactive base question
cout<<"Please give me the base you ";
cout<<"would like to use[2-36]: ";
cin>>base;
//Make sure not to calc a value that's too high or low
if((base > 36) || (base < 2))
{
cout<<"This program can't calculate ";
cout<<"a base over 36 or under 2"<> i1)
{
printBase(i1); //<-Where the actual work is done
cout << endl;
}
return 0;
}