I wrote this code it seemed to good but the output is always 0 what could be the problem? I m just writing a code to convert from x number system to decimal.
#include <string>
#include <iostream>
using namespace std;
int main() {
string str;
long szam = 0, Dec, num, Base = 1, x,i=1;
cout << "the number : ";
cin >> str;
cout << "The input number system:";
cin >> x;
while (str[i] == '\0')
{
if (str[i] = 'A') { num = 10;}
else if (str[i] = 'B') { num = 11; }
else if (str[i] = 'C') { num = 12; }
else if (str[i] = 'D') { num = 13; }
else if (str[i] = 'E') { num = 14; }
else if (str[i] = 'F') { num = 15; }
else { num = str[i] - '0'; }
Dec = Dec + num * Base;
Base = Base * x;
}
cout << szam << endl;
return 0;
}
If x smaller than 10 its easy but i cant handle the 10+ system because of the letter use of numbers.