1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
double convertb10(char number[],int base)
{
double z = 0;
double x = 0;
char conversion[16] = {'0','1','2','3','4','5','6',
'7','8','9','A','B','C','D','E','F'};
double convert[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
for (int y = 0; y <= 20; y++)
{
for (int i = 0; i < 16; i++)
{
if (!(strcmp(number[y],conversion[i])))
{
x += (convert[i] + pow(10,z));
z++;
}
}
}
return x;
}
int main()
{
char number[20];
int base, convert;
cout << "Please enter the number, the base, and the base to be converted: ";
cin >> number >> base >> convert;
double b10num = convertb10(number,base);
cout << b10num;
system("PAUSE");
return EXIT_SUCCESS;
}
|