i need to be able to convert any number to base ten after being given the number and base.
i so far am unable to run the code. Any help would be great. thanks
#include <iostream>
#include <cmath>
using namespace std;
void baseConverter(int number, int base);
const char digits ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
int result;
int number, base;
int main () {
cout << "This program will ask for a base of a number\n";
cout << " and the number itself and convert your number\n";
cout << " to base ten\n";
while (true) {
cout << "Please enter a number and then the numbers base: ";
cin >> number, base;
if (base < 2 || base >36) break ;
cout << "Bases must be from 2 to 36 to convert. Please try again" << endl;
}
result= baseConverter(number,base);
cout << "The converted base 10 number is: "<<result;
cin.get();
cin.get();
return 0;
}
void baseConverter(int number, int base)
{
int sum = number%10;
for (int i=base; (number/=10)!=0; i*=base)
sum+= number*i;
return sum;
}
Edited by Dogstopper:

New Topic/Question
Reply




MultiQuote






|