I've been trying for 2 days now to get this code to work. It's just been error after error.
Can anyone point out what i'm doing wrong?
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
int h = 0;
for(int a = 100; a<1000; a++)
for(int b = 100; b<1000; b++)
int c = a * b;
// Error: "c" is undefined
if ((c == reverse(c)) && (c > h))
h = c;
cout << "The answer is: " << h << endl;
}
int reverse (int x)
{
// Error: "'itoa' : function does not take 1 arguments"
string s = string(itoa(x));
reverse(s.begin(), s.end());
return (x);
}
Using std::to_string just gives me more errors as well.
When your compiler explains something to you in an error message, you should believe it.
itoa
does, in fact, take more than one argument, as you can see at the following link:http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/
Edit: Oh and this is achievable using standard, C++-style code by the way (fixed a bit of code as per suggestion in the comments):
Here. Not sure it's the cleanest solution but it works on my compiler.
Edit: Found out how to use only one stringstream here : How to clear stringstream?