Here's what I have so far. I am trying to enter a number and convert the number entered into hours, minutes and seconds. I must use "pass by reference" in my code.
#include<stdio.h> void time(int, int*, int*, int*); //Function Prototype int main(void) //function header { int hold; float total; printf("Enter the number of seconds ->"); scanf("%d",&total); scanf("%d", &hold); return 0; } // end of main function void time (int total, int *hours, int *min, int *sec) // Function header Line { int rem1, rem2; *hours = total / 3600; rem1 = total % 3600; *min = rem1 / 60; rem2 = rem1 % 60; printf ("the number of hours is ->", *hours); printf ("the number of minutes is ->", *min); printf ("the number of seconds is ->", *sec); }
Here are some observations on the code you have posted.
- I'm not sure why you have declared the variable hold. I'm assuming that the variable total is supposed to be the total number of seconds that will be the input to your time function. That being the case, then it should be declared as int.
- In main you don't even call your time function. You haven't declared variables for hours, minutes and seconds as well. These should be declared and their addresses should be passed to the time function you have defined (there's your pass by reference).
- In your time function, you haven't calculated the number of seconds and you don't need the rem2 variable …