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.
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.
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. :)