Wtf is wrong with this code(simple one) ?????

0 Alex Carter · April 14, 2015
Here is very simple cod, it doesn't have errors, but it doesn't work.

#include <stdio.h>

void izFuC(int f, double c) {
c = (f - 32) * 5/9;

int main(void) {
int f=89;
double c=0;
izFuC(f, c);
printf("F=%d pretvoreno u C=%lf",f,c);

return 0;

Post a Reply


Oldest  Newest  Rating
+2 c student · April 15, 2015
make the return type of izFuC a double and return it

double izFuC (int f, double c) {
return (f - 32) * 5/9;

int main (void) {
/* your code here */

printf("F=%d pretvoreno u C=%lf",f, izFuC (f, c));

return 0;

you can return it directly into printf(), making a return into a variable a redundant procedure unless you plan to reuse the value.
+1 Dol Lod · April 15, 2015
You are not modifying c by reference so all changes made will be local to the function.

To fix this 

1) Simple solution is have c=izFuC(f,c) to set the value of c after the function call.

2) A more advanced solution is to pass in a pointer to c and do *c=(f-32)*5/9

void izFuC)int f, double* c)

You get the address of a variable by using &. 
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator