Author Topic: what is wrong with my code?  (Read 370 times)

Offline Yang_CH

  • Single posting newcomer
  • *
  • Posts: 1
what is wrong with my code?
« on: October 26, 2019, 03:37:22 pm »
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;
}
//----------------------------------------------------------------
« Last Edit: October 26, 2019, 03:40:18 pm by Yang_CH »

Offline cacb

  • Regular
  • ***
  • Posts: 397
Re: what is wrong with my code?
« Reply #1 on: October 26, 2019, 04:48:53 pm »
This is not a general programming board, read this
http://forums.codeblocks.org/index.php/topic,9996.0.html

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2545
Re: what is wrong with my code?
« Reply #2 on: October 27, 2019, 07:36:37 pm »
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!
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....

Offline sodev

  • Regular
  • ***
  • Posts: 329
Re: what is wrong with my code?
« Reply #3 on: October 27, 2019, 10:08:52 pm »
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.