User forums > Help

what is wrong with my code?

(1/2) > >>

Yang_CH:
Hello, Everyone,
My c++ code is as below, my input is: 10.0.3.193, the output of which is 192. But with other IDE and the the same code and input, I got output of 193, which is what I expect. what is the cause? Thanks!
//----------------------------------------------------------------
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int temp=0;
    for(int i=str.rfind('.')+1;i<str.length();i++)
    {
        temp+=(str-'0')*pow(10,str.length()-i-1);
    }
    cout<<temp<<endl;
    return 0;
}
//----------------------------------------------------------------

cacb:
This is not a general programming board, read this
http://forums.codeblocks.org/index.php/topic,9996.0.html

BlueHazzard:

--- Quote ---My c++ code is as below, my input is: 10.0.3.193, the output of which is 192. But with other IDE and the the same code and input, I got output of 193, which is what I expect. what is the cause? Thanks!
--- End quote ---
i do not think so.. Your code is wrong on so many levels.... I even do not understand how you can compile this. Your posted code is not valid c++ code....

sodev:
The "code" suddenly starts to become italic, im pretty sure some array indices became formatting commands, thats why you should post code always in code tags.

So this might compile, but i do not know and do not want to know what this is supposed to do.

sodev:
Why i can't see any difference between the bug and your correction? Why i can see italics again?

This is getting really scary...

Navigation

[0] Message Index

[#] Next page

Go to full version