error: expected identifier... / project euler 4

Aug 20, 2012 at 5:42pm
I am trying to do project euler # 4. My code gets an error: expected identifier before '(' token. This is on line 28.


I'm not sure if this works or not since it won't compile, but feel free to give any comments on the code etc. Thanks!
Last edited on Aug 21, 2012 at 12:46am
Aug 20, 2012 at 5:51pm
if ((a == d) && (c == d))


Also, this: if (100 < z < 1000){
does not do what you want. i expect you mean:
if ((100 < z) && ( z < 1000)){

Likewise the others.
Last edited on Aug 20, 2012 at 5:52pm
Aug 20, 2012 at 6:18pm
Yes!!! Thanks! I also had to get rid of the break statements and add another && to the if statements. Should I post my code?
Aug 20, 2012 at 10:54pm
Yes please. I want to modify it so that it can find it for any length number.
Aug 21, 2012 at 12:48am
As you wish.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
/* A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91  99.

Find the largest palindrome made from the product of two 3-digit numbers. */
using namespace std;

int main()
{
  int v = 0;
  int a, b, c, d, e, f;
  int x = 999;
  int y = 999;
  int z = a * x;
            while (y > 0){
    if ((100 < z) && (z < 1000)){
    a = z % 10;
    b = ((z % 100) - a) / 10;
    c = ((z % 1000) - a -(10 * b)) / 100;
        if ((a == c) && (z > v)){
         v = z;
        }
    }
    if ((1000 < z) && (z < 10000)){
    a = z % 10;
    b = ((z % 100) - a) / 10;
    c = ((z % 1000) - a -(10 * b)) / 100;
    d = ((z % 10000) - a - (10 * b) - (100 * c)) / 1000;
          if ((a == d) && (c == d) && (z > v)){
         v = z;
         }
    }
    if ((10000 < z) && (z < 100000)){
    a = z % 10;
    b = ((z % 100) - a) / 10;
    c = ((z % 1000) - a -(10 * b)) / 100;
    d = ((z % 10000) - a - (10 * b) - (100 * c)) / 1000;
    e = ((z % 100000) - a - (10 * b) - (100 * c) - (1000 * d)) / 10000;
        if ((a == e) && (b == d) && (z > v)){
        v = z;
        }
    }
    if ((100000 < z) && (z < 1000000)) {
    a = z % 10;
    b = ((z % 100) - a) / 10;
    c = ((z % 1000) - a -(10 * b)) / 100;
    d = ((z % 10000) - a - (10 * b) - (100 * c)) / 1000;
    e = ((z % 100000) - a - (10 * b) - (100 * c) - (1000 * d)) / 10000;
    f = ((z % 1000000) - a - (10 * b) - (100 * c) - (1000 * d) - (10000 * e)) / 100000;
        if ((a == f) && (b == e) && (c == d)&& (z > v)){
        v = z;
        }
    }

    x --;

    if (x == 1){
y --;
x = 999;
}
    z = y * x;
    }
cout << v << endl;
    return 0;
}
Topic archived. No new replies allowed.