 # Can you tell why this doesn't fully work?

Thanks to the good prompts in x-code I was able to get this challenge done, but I had to do it pretty differently from how it was done with the floor() function.

My main question is why the final print function works when I put it in the metersToFeetAndInches function and not when I call it in the Main function. I can’t see what I am doing wrong. The print functions in question have BOLD COMMENTS right before them.
Thanks!

[code]//
// main.c
// Meters
//
// Created by James Plauche on 7/27/15.
// Copyright © 2015 Tanner Plauché. All rights reserved.
//

#include <stdio.h>
#include <math.h>

void metersToFeetAndInches (double meters, double *ftPtr, double *inPtr){
//This function assumes meters is non-negative.

``````// convert the number of meters into a floating point number of feet.
double rawFeet = meters * 3.281; //e.g. 2.4536
printf("%f\n", rawFeet);
``````

//Assign inches to rawinches by returning what is right of the decimal. store what is to the left at the pointer ftPtr.
double rawInches = modf(rawFeet, ftPtr);
double inches = rawInches * 12;
printf(" There are %.3f inches. \n", inches);

``````// Assign what is at ftPtr to feet.
double feet = *ftPtr;
printf("There are %.1f feet. \n", feet);

//THIS PRINT works when I put it in the function.
printf("%.1f meters is equal to %f feet and %.3f inches.", meters, feet, inches);

}
``````

int main(int argc, const char * argv[]) {

``````double meters = 3.0;
double feet;
double inches;

metersToFeetAndInches(meters, &feet, &inches);

//THIS PRINT doesn't work when it is in main.
printf("%.1f meters is equal to %f feet and %.3f inches.", meters, feet, inches);

return 0;
``````

}
[/code]

Output is:

```9.843000 There are 10.116 inches. There are 9.0 feet. 3.0 meters is equal to 9.000000 feet and 10.116 inches.3.0 meters is equal to 9.000000 feet and 0.000 inches.```

To do that, set the values of the pass-by-reference parameters.

Compare:

``````//  main.c - Pass values by reference

#include <stdio.h>
#include <assert.h>
#include <math.h>

void metersToFeetAndInches (double meters, double *ftPtr, double *inPtr){

//This function assumes meters is non-negative.
assert (meters >= 0);

// convert the number of meters into a floating point number of feet.
double rawFeet = meters * 3.281; //e.g. 2.4536
printf("%f\n", rawFeet);

//Assign inches to rawinches by returning what is right of the decimal.  store what is to the left at the pointer ftPtr.
double rawInches = modf(rawFeet, ftPtr);
double inches = rawInches * 12;
printf(" There are %.3f inches. \n", inches);

// Assign what is at ftPtr to feet.
double feet = *ftPtr;
printf("There are %.1f feet. \n", feet);

printf ("%s: %.1f meters is equal to %f feet and %.3f inches.\n", __func__, meters, feet, inches);

// Because they are pass-by-reference parameters,
// we can pass the values back to the caller in the last two parameters.
* inPtr = inches;
* ftPtr = feet;
}

int main (int argc, const char * argv[]) {

double meters = 3.0;
double feet;
double inches;

metersToFeetAndInches(meters, &feet, &inches);

printf ("%s: %.1f meters is equal to %f feet and %.3f inches.\n", __func__, meters, feet, inches);

return 0;
}``````

When you understand how pass-by-reference works, you have become an Objective-C programmer.