944,087 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 7513
  • C++ RSS
Dec 4th, 2004
-1

I cant correct these two errors

Expand Post »
hi all....I need help with a pragram which i wrote .....Itz to check if a number is palindrome or not using a function...i.e. the program will ask the user to input any number....then if u reverse the number it will give u the same old number then it is a palindrome number....For Example: if the user enters 121 ...then if u reverse it will give u the same number 121..and so 121 is a palindrome number.....The program which i wrote is below:

#include<iostream.h>

int palindrome(int n)

{

int x, m=0;
while(n>0)

{

x=n%10;

m*=10;

m+=x;

n/=10;

}

return m;

}

void main()

int n, y;

cout<<"Enter any number"<<endl;

cin>>n;

y=palindrome(n);

if(n==y)

cout<<"The entered number is a palindrome number "<<endl;

else

cout<<"The entered number is not a palindrome number "<<endl;


}


_______________________________________________________________

The errors of the program are:


:warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
: error C2146: syntax error : missing ';' before identifier 'n'
: fatal error C1004: unexpected end of file found
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004
Dec 4th, 2004
0

Re: I cant correct these two errors

Hi, just wondering what complier you're using. I compiled your code with Borland C++ 5.5.1 and obtained the following error messages.

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
palindrome.cpp:
Error E2141 palindrome.cpp 28: Declaration syntax error
Error E2141 palindrome.cpp 30: Declaration syntax error
Error E2141 palindrome.cpp 32: Declaration syntax error
Error E2303 palindrome.cpp 34: Type name expected
Error E2451 palindrome.cpp 34: Undefined symbol 'n'
Error E2040 palindrome.cpp 36: Declaration terminated incorrectly
Error E2040 palindrome.cpp 40: Declaration terminated incorrectly
Error E2190 palindrome.cpp 45: Unexpected }
*** 8 errors in Compile ***

All that I did next is to correct the very last error. After inserting a brace '{' after line 26 (i.e. after the code 'void main()'), the code compiled without error. I think that's all that you missed.



Quote originally posted by Extreme ...
hi all....I need help with a pragram which i wrote .....Itz to check if a number is palindrome or not using a function...i.e. the program will ask the user to input any number....then if u reverse the number it will give u the same old number then it is a palindrome number....For Example: if the user enters 121 ...then if u reverse it will give u the same number 121..and so 121 is a palindrome number.....The program which i wrote is below:

#include<iostream.h>

int palindrome(int n)

{

int x, m=0;
while(n>0)

{

x=n%10;

m*=10;

m+=x;

n/=10;

}

return m;

}

void main()

int n, y;

cout<<"Enter any number"<<endl;

cin>>n;

y=palindrome(n);

if(n==y)

cout<<"The entered number is a palindrome number "<<endl;

else

cout<<"The entered number is not a palindrome number "<<endl;


}


_______________________________________________________________

The errors of the program are:


:warning C4518: 'int ' : storage-class or type specifier(s) unexpected here; ignored
: error C2146: syntax error : missing ';' before identifier 'n'
: fatal error C1004: unexpected end of file found
Reputation Points: 10
Solved Threads: 1
Newbie Poster
khkwa is offline Offline
12 posts
since Nov 2004
Dec 4th, 2004
0

Re: I cant correct these two errors

IF THIS IS THE SAME CODE U HAVE TRIED THEN I THINK THE ONLY ERROR IS THAT AFTER
void main()
U HAVE NOT GIVEN THE BRACES AND THATS WHY THE COMPILER IS RELATING IT WITH A CLSS;
SO GIVE THE BRACES
void main()
{

like this and i hope ur problem will be solved
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Dec 4th, 2004
0

Re: I cant correct these two errors

sorry, i didn`t notice that KHKWA has already solved the problem just a few moments before me. so my suggestion was needless
Reputation Points: 10
Solved Threads: 1
Light Poster
varunrathi is offline Offline
41 posts
since Aug 2004
Dec 6th, 2004
0

Re: I cant correct these two errors

I use Microsoft visual C++ 6.0....

Do u know watz da mistake in my program?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Extreme is offline Offline
12 posts
since Nov 2004
Dec 6th, 2004
0

Re: I cant correct these two errors

if you read back a few replies you'll see the answer to that.

Learning to read compiler output can be a bit tricky but is extremely helpful.

Tutorials and teachers should spend time on it (even though different compilers produce different output the principles remain the same), sadly most don't and just expect everything to compile first time...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c.COM
Next Thread in C++ Forum Timeline: OnInitUpdate





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC