the assignment is: have a number saved in a string, then convert from a string to an integer–> convert that number to a decimal number from N-base the user inputs.
#include <iostream>
using namespace std;
int main()
{
string snum;
int n=0, base, res;
cout << "enter n: ";
cin >> snum;
cout << "enter base: ";
cin << base; //THIS IS LINE 13
for (int i=0; i<snum.length(); i++) // des order
{
int digit = snum.at(i) - '0';
n = (n*1) + digit;
if (
base <= 10
) res = base * n;
cout << "n is " << res << endl;
}
}
Im getting error: NO MATCH BETWEEN SIGNED AND UNSIGNED INTEGER EXPRESSIONS [Line 13]
ty all!!
*if u find any problems in logic please let me know!
*using codeblocks
with
you mean
EDIT:
you should convert the number differently, instead of grabbing each character take the whole string and convert it to a number. You can use a stream for that or just atoi( sum.c_str() ) to get the integer number.
thereafter convert the value to whatever base you want.
e.g.