Beginner, need guidence in this program

Hello. My task is to take a user's input and output that value in hours:minutes:seconds form. This is what I have so far.

#include <iostream>
using namespace std;

int userSeconds;
int seconds;
int minutes;
int hours;
int remainder;

int secondsHoursMinutes(int seconds, int minutes, int hours, int remainder)
{
hours = (userSeconds / 3600); // Get hours by dividing seconds by 3600
remainder = (userSeconds % 3600); // Get remainder by dividing seconds by 3600
minutes = (remainder / 60); // Get minutes by dividing the remainder by 60
remainder = (minutes % 60); // Get seconds by dividing
seconds = remainder;

return 0;
}

int main()
{
cout << "Please enter the seconds as an integer" << endl;
cin >> userSeconds;
cout << userSeconds << " in hours:minutes:seconds form is " <<
hours << ":" << minutes << ":" << seconds << endl;

system("pause");
return 0;
}


Yes, it does not work. I would just like to know if I am on the right track with this program. Any suggestions would be appreciated.
Ah... you would like to pass those variables by reference, I see.
http://cplusplus.com/doc/tutorial/functions2/

See if this helps!

-Albatross

EDIT: Sweet 17 (hundred) posts, and counting.
Last edited on
I viewed that, and I realized that I should be using a void function, but I still do not know why I am getting 0:0:0 as my output, even when I enter 3600. Should this not return 1:0:0? Or am I completely lost.
Wait... you never call your function! Silly me for not noticing that. You need to call your function before the second cout and after the first cin, else your variables won't be changed.

Oh, and you ARE passing by reference, right?

-Albatross
Last edited on
I put an & before each of the variables, but how will I call it if I'm not calling it by value? Would I just put secondsHoursMinutes; ??
You call a function that takes variables by reference just as you would any other function. The difference is that your function that muck about with your variables and not just their values. :)

-Albatross
Last edited on
Ahhhhh I got it now. Thanks for your help!!
Topic archived. No new replies allowed.