need help with compiling some simple lines of code

code is below. compiling errors and warnings are at the bottom of the page. help is much appreciated.



1 #include <iostream>
2
3 using namespace std;
4
5 bool solver(int *input, int *checker, int length)
6 {
7 int j, k, l = 0, count =0;
8
9 //checking for repeated digits
10 for (j = 0, j < length, j++)
11 {
12 for (k = j + 1, k < length, k++)
13 {
14 if (input[j] == input[k])
15 return false;
16 }
17 }
18 //scans through the digits to check if the number is a run around number
19 while (checker[l] < 2 && count <= length)
20 {
21 //checker is a array thats been initialized to 0, if number is checked once, its value is 1 and 2 is it is checked twice
22 checker[l] += 1;
23 //since a number 147 is stored as 7 4 1 , checking goes from right to left, hence minus sign
24 l -= input[l];
25 while (l < 0)
26 {
27 l += length;
28 }
29 //count is included because for a 3 digit number max number of scan throughs for a runaround number is 4, with the first digit checked twice
30 count++;
31
32 }
33
34 if (checker[0] == 2)
35 {
36 return true;
37 }
38 else
39 return false;
40 }
41
42 int main(void)
43 {
44 int input[9] = {0};
45 int checker[9] = {0};
46 int number, i = 0, length = 0;
47 bool x = false;
48 cin >> number;
49
50 while (x == false)
51 {
52 // number++ for next greater number
53 number++;
54 while(number !=0)
55 {
56 input[i] = number%10;
57 number /= 10;
58 length++;
59 i++;
60 }
61 // if x is true, loop terminated and number is printed out, if x is false, check if next greater number is a runaround number.
62 x = solver(input, checker, length);
63 }
64
65 cout << number << endl;
66
67 return 0;
68 }

-----------------end of code--------------------

errors and warnings in compiling

lab111.cpp: In function ‘bool solver(int*, int*, int)’:
lab111.cpp:10:26: warning: right-hand operand of comma has no effect
lab111.cpp:10:28: error: expected ‘;’ before ‘)’ token
lab111.cpp:68:1: error: expected primary-expression at end of input
lab111.cpp:68:1: error: expected ‘;’ at end of input
lab111.cpp:68:1: error: expected primary-expression at end of input
lab111.cpp:68:1: error: expected ‘)’ at end of input
lab111.cpp:68:1: error: expected statement at end of input
lab111.cpp:7:8: warning: unused variable ‘k’
lab111.cpp:7:11: warning: unused variable ‘l’
lab111.cpp:7:18: warning: unused variable ‘count’
lab111.cpp:68:1: error: expected ‘}’ at end of input
lab111.cpp:68:1: warning: no return statement in function returning non-void
Can you repost this with code tags? With just a quick look you need to use the ";" character in the for loops not the "," character.
thanks alot man. that was the only error in the code. compiles fine now.
Last edited on
Topic archived. No new replies allowed.