Monday, July 27, 2009

C++ help. whats wrong with this programme. pls tell or i'll go mad.?

here is my c++ programme to reverse a number. i get an error in line 5 saying "expected }" and a warning in line 5 saying "sign of function defination is now obsolete"


pls tell me whats wrong.





#include%26lt;iostream.h%26gt;


#include%26lt;conio.h%26gt;





int reverse( *num,*rev,*rem) // line 5


{


int i,rev=0,rem=0;


for(i=0;i%26lt;3;i++)


{





rem=num%10;


num=num/10;


rev=(rev+rem)*10;


}





return rev;





}








void main()


{


int num;





cout%26lt;%26lt;"enter a number to reverse";


cin%26gt;%26gt;num;





reverse(num,rev,rem,i);


cout%26lt;%26lt;rev;


}

C++ help. whats wrong with this programme. pls tell or i'll go mad.?
This code has many problems!!!!


1. reverse is declared as a function so it cannot be used as a void!


2. you didn't declare rev,rem in the main procedure, so the call is invalid! (you have to declare them either inside the main procedure, as local variables or at the begining, as global variables, but they must be declared!!!)


3. the compiler doesn't understand a thing from how you declared reverse function! I know you wanted to transfer the parameters by their address and not by their value but this isn't the way to do it!!!)


4. the function is declared as returning an int, but this isn't what your function is returning! You're returning the adress to an int!!!!





Hope it's more clear now!! If now pls e-mail me!
Reply:u need to change the entire program.





better tell what u r trying to do.





the following are wrog:





ur function definition does not match the function call





u need to have datatypes of arguments defined in the function definition





the function returns something. it should be saved.





since, rev is not global(its value is not preserved in main) u cannot print rev like that in main()
Reply:There are quite a lot of problems in this program , no problems dont' just get disheartened.


1. You have not declared your num, rev and rem variables in the main() func.


2.your functions returns the address and not the value


3.some of your arithmetic seems vague and bizzare.





Just kp prgmming.


No comments:

Post a Comment