stuck with defined function

hi, i have small proplem can someone try to fix it, it is neccesary to keep the function before int main() ?

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
66
67
68
69
70
71
72
73
74
75
76
 #include <iostream>

#include <cmath>

using namespace std ;

int length ( int num )
{
	int digits = 0 ;

	if ( num == 0 )
	digits = 1;

	while ( num != 0 )
	{
		digits++ ;
		num = num / 10 ;
	}

	return digits ;
}

bool isPalindrome(int num)
{
  int pwr = 0;

  if(num < 10)
		return true;
  else
  {
   while(num / static_cast<int>(pow(10,pwr)) >= 10)
		      pwr++;

     while(num >= 10)
     {
	      if((num / static_cast<int>(pow(10,pwr))) != (num % 10))
		      return false;
else
		  {
	         num = num % static_cast<int>(pow(10,pwr));

	  	     num = num / 10;
	         pwr = pwr - 2;
	      }
	 }

    return true;
  }




int main ()
{

	int num , digits = 0  ;


	cout << "Enter an integter : " ;
	cin >> num ;

digits = length(num);

	cout << "The number of digits in your integer is " << length(num)<<endl;

	isPalindrome (num);

	if ( isPalindrome (num) == 1 )
			cout << "It is a Palindrome" << endl ;
		else
			cout << "It is not a Palindrome" << endl ;

	return 0 ;
}
}
Use proper indentation and it will be more obvious where the problem is.

Hint: It's not possible to define functions inside other functions.
the codebloks get 1 error with error: a function-definition is not allowed here before '{' token|

line 54
You have an extra } on line 75, remove that. Also you have a missing } on function isPalindrome, add a } to close off the function.
it is neccesary to keep the function before int main() ?


No it's not, you just have to provide a declaration before the first call of the function;

 
void SomeFunction(int, int); // <-- This is a declaration 
Last edited on
Topic archived. No new replies allowed.