Minor Problem with Code

I created a program based off this Project Euler problem. https://projecteuler.net/problem=4
I managed to get my program to work, however it doesn't work the way I expect it to. I've had my teacher look over it and even he can't understand why it doesn't perform the way I expect it to. Perhaps the expert programmers here could help me figure out what's off.

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
ostringstream convert;
string check, reversed;

const int largest3dignum = 999;
long currentnum;
long largestpalindromic;

for(int x=100; x<=largest3dignum; x++)
{
for(int y=100; y<=largest3dignum; y++)
{
currentnum=x*y;

convert << currentnum;
check = convert.str(); //converts the current number to string
reversed = string(check.rbegin(), check.rend()); //reverses string and stores in reversed
if(check==reversed) //if both strings are equal the current number becomes the largest palindrome
largestpalindromic = currentnum;
}
}

cout << "The largest palindrome is " << largestpalindromic << endl;

return 0;
}

As you see my primary method of identifying a palindrome is converting the current calculated value to a string, and the inverting that string (stored in another string variable) and compare both strings to see if they match. If so the number being calculated is named the largest palindrome until another is found.
I look forward to your responses.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
    ostringstream os;
    const unsigned limit = 10;

    for (unsigned i = 0; i < limit; ++i)
    {
        os << i;
        std::cout << os.str() << '\n';
    }
}
0
01
012
0123
01234
012345
0123456
01234567
012345678
0123456789


std::to_string would be more appropriate here.
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/general/177482/#msg875307
Topic archived. No new replies allowed.