"Function" Problem..

Can somebody solve/write this code for me??? I will need the answer to this for a reference for the other 9 problems...

(a) Write a function named time () that has an integer parameter named seconds and three integer reference parameters named hours, min, and sec. The function is to convert the number of seconds passed to it from the main program into an equivalent number of hours, minutes and seconds.
(b) Write a program that inputs an integer number for seconds, calls the function, and displays the equivalent number of hours, minutes, and seconds.
1
2
3
4
5
6
void time(int seconds, int &hours, int &min, int &sec)
{
hours = seconds/3600;
min = seconds%3600/60;
sec = seconds%60;
}
#include <iostream>

using namespace std;

void time(int, int*, int*, int*);

int main()
{
int secnds, hrs, min, sec;

cout << "Enter the time in seconds: " ;
cin >> secnds;

time(secnds, &hrs, &min, &sec);
cout << "The time changed in hour is => ";
cout << hrs << " : " << min << " : " << sec;
cout << endl;
cout << endl;
cout << "The number of hours is: " << hrs;
cout << endl;
cout << "The number of minutes is: " << min;
cout << endl;
cout << "The number of seconds is: " << sec << "\n";

return 0;
}

void time(int secnds, int *hrs, int *min, int *sec)
{
int mod1, mod2;

*hrs = secnds/3600;
mod1 = secnds%3600;
*min = mod1/60;
*sec = mod1%60;

}
Topic archived. No new replies allowed.