0

Hello fellow programmers :))
just started c++ a month ago and in need of major helpzz!!

so basically I need code that:
INPUT NUMBER-->BASE OF NUMBER-->PRINTS DECIMAL REPRESENTATION OF IT

Im trying this code..when i put any number and base I just get 0

pleaxxxx help!!!

ty all!!

#include <iostream>
#include <cmath>

using namespace std;


int main()
{

    string inp;
    int j;
    int dec=0;  //store
    char base;
    cout << "input number: ";
    cin >> inp;
    cout << "input base: ";
    cin >> base;
    for (int i = inp.length ()-1; j == 0; ++j) dec += (inp[i]-48) * pow ((float) base-48,j);
    cout << "your number in base 10 is: " << dec << endl;

return 0;
}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Taywin
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.