english to decimal
#include<iostream>
#include<cmath>
#include<limits>
#include<string>
void print_value(const size_t value);
// bool IllegalCharacters(int,const std::string, int);
bool isalpha_isspace(const std::string&);
int main()
{
std::string eng2dec;
std::cout<<"\nPlease enter a string of small letters and spaces:\t";
getline(std::cin,eng2dec);
// checking if string is an alphabet or spaces
bool answer = isalpha_isspace(eng2dec);
if(answer == false)
{
std::cout<<"\nThe input string does not represent a number in base 27"<<std::endl;
exit(1);
}
// looping throught the string and converting the value of chars to decimal with base 27
size_t value {0};
int decimal {0};
for(size_t i {0}; i<eng2dec.length(); ++i)
{
if(eng2dec[i]==' ')
{
decimal=0;
}else{
int power = (eng2dec.length()-1-i);
decimal = eng2dec[i]%96;
value+= decimal*pow(27,power);
}
if(value > pow(2,32)){
std::cout<<"\nThe input string represents a number that is greater than 2ˆ32" <<std::endl;exit(1);
}
}
print_value(value);
return 0 ;
}
// check if string is not alphabet or space
bool isalpha_isspace(const std::string& str )
{
bool answer ;
for(char c: str){
if(isalpha(c) || isspace(c))
{
answer = true;
}else
{
answer= false;
}
}
return answer ;
}
// print value
void print_value(const size_t value){
std::cout<<value<<std::endl;
}