//Jordan Steffen
//stej4019 - cs201-807
//prog12.cc
/*purpose: ask user to enter values then convert
number in given base to its base 10 equivalent
and display a reasonable report.*/
#include <iostream>
#include <cmath>
using namespace std;
void welcome();
bool isDigit(char c);
int digit2Int(char c);
int isValidDigit(char c, int base);
int main()
{
welcome();
int base;
cout<<"Please enter the number's base [2, 10] : ";
cin>>base;
while(!(base >= 2 && base <= 10))
{ cout<<"Please enter the number's base [2, 10] : ";
cin>>base;
}
int counter = 0;
while(counter < 6)
{
int i = 0;
cout<<"Please enter digit "<<counter<<" [0, "<<base - 1<<"] : ";
cin>>i;
counter += 1;
}
return 0;
}
void welcome()
{
cout<<endl<<"-----------------------------------------------------"<<endl<<
" Welcome to the CS201 exam base conversion program"<<endl<<
"-----------------------------------------------------"<<endl<<endl<<
"You will first be asked for the base of your number"<<endl<<
"which must be between 2 and 10 inclusive."<<endl<<endl<<
"Next You will repeatedly be asked to enter the digits"<<endl<<
"of your number (right to left). If you enter a"<<endl<<
"non-digit you will be given the opertunity to either"<<endl<<
"re-enter the mistaken digit or quit the data entering"<<endl<<
"and proceed to the report."<<endl<<
"------------------------------------------------------"<<endl<<endl;
}
bool isDigit(char c)
{
return ((c >= '0') && (c <= '9'));
}
int digit2Int(char c)
{
return (c - '0');
}
int isValidDigit(char c, int base)
{
if(isDigit(c))
{
if(base > digit2Int(c))
return digit2Int(c);
}
return -1;
}