Code::Blocks Forums
User forums => Help => Topic started by: Yang_CH 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;
}
//----------------------------------------------------------------
-
This is not a general programming board, read this
http://forums.codeblocks.org/index.php/topic,9996.0.html
-
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....
-
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.
-
Why i can't see any difference between the bug and your correction? Why i can see italics again?
This is getting really scary...
-
Why i can't see any difference between the bug and your correction? Why i can see italics again?
This is getting really scary...
Sorry after realizing what it was wrong with code I decided remove message due it violate rules.
Again italic come from the code of poster.
This forum has no preview mode and posted text was the only help discovering what was wrong on original code. str-'0' extract one character by using i as index, square braces used for array indexing where interpreted as italic command.
Original poster problem remain unaddressed but answer where more confusing than original post.
Code has nothing wrong in it than how is there due to "["i"]" translation to italic.
Sometimes explain how to use "code tags" is better than just do confuse more who is reading about.
As I wrote on erased message:
Newbie forever discover hidden feature of environment.