开发者

error: comp. bet. signed/unsigned integer expressions CODEBLOCKS

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 * 开发者_JS百科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

cin << base; //THIS IS LINE 13

you mean

cin >> base;

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.

snum=12 (converted to integer from input string)
base=8

12 - 8 (>8, number of times you can subtract) --> 1
4 - 8 (<8 use remainder) --> 4

output == 14
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜