Write a program that will accept from the user the total number of seconds. Pass this value along with the addresses of three variables – hours, minutes, seconds – to a function called time() that will calculate the number of hours, minutes and seconds. Print this information from main().
Help me plz how can i fix my code to make this program work the way it supposed to.
/* Adham Hamade
.
*/
#include <stdio.h>
#include <conio.h>
//function prototype
void time(int &,int &,int &, int);
int main()
{
//Variables
int num;
int hours;
int minutes;
int seconds;
//reference number variables
int *h = &hours;
int *m = &minutes;
int *s = &seconds;
printf("Please enter number of seconds");
scanf("%d",&num);
time(h, m, s, num);
printf("\n\nTime is %d hrs %d mins %d secs", hours, minutes, seconds);
getch();
return 0 ;
}
void time(int &h,int &m ,int &s, int num)
{
int sec;
int min;
int hr;
int t;
hr = num / 3600 ;
t = num %3600;
min = t/60;
sec = t%60;
hr = &h;
min = &m;
sec = &s;
}
printfformat strings with\nor else callfflushh,mandsvariables, and just calltimeastime(&hours, &minutes, &seconds, num). That function has to take pointers; there are no reference parameters in C.timefunction in the C language, so when you define your own external function calledtime, you're invoking undefined behavior.