Whatever you do in the submitted code, you are not using the double data type at all, inside the function. And from the return type of the function, it looks like you will never see the return value> 127.
This code highlights some issues: (This is just illustrative)
char hexRepresentation(double n){ if(n > 9){//comparing (double>int). Bad. if(n==10) return 'A'; if(n==11) return 'B'; if(n==12) return 'C';//You wrote if(double == int). Bad. if(n==13) return 'D'; if(n==14) return 'E'; if(n==15) return 'F'; } return (char)n; //again unsafe downgrade from 8 bytes double to 1 byte char. }
Even if you fix a compiler error, you may not always get the desired results because of such a dangerous use of the data type in a function.
To find out why this is bad, look here:
http://www.cygnus-software.com/papers/comparingfloats/Comparing%20floating%20point%20numbers.htm
I would use fabs(n) instead of n everywhere in this function body.
And the error "conflicting types for" hexRepresentation "will be shown if there is a preliminary declaration or definition of the same named hexRepresentation function before this function hexRepresentation . In addition, if you do not declare the function and it appears only after the call, it is automatically considered an int compiler.
So, declare and define your function before main () or declare it before main () and define the function elsewhere in the file, but with the same function prototype.
Do:
char hexRepresentation(double);
or
char hexRepresentation(double n){
source share