-3

I have a C++ code to convert seconds and minutes but it seems like whenever it convert the second, it won't update the minute. How can I fix it?

#include <iostream>
using namespace std;

void Convert(int value, int &hour, int &minute, int &seconds)
{
    hour=value/60;
    minute=value%60;
    seconds=value%60;
}

int main()
{
    int hour;
    int seconds;
    int Seconds_To_Convert = 90;
    int minute;
    int Minutes_To_Convert = 70;

    //calling Convert function
    Convert(Minutes_To_Convert, hour, minute, seconds );

    //compute
    cout<<hour <<" hours and "<<minute<<" minutes "<<"and "<<seconds<<" seconds ";
    return 0;
}

Thanks

Cael
  • 556
  • 1
  • 10
  • 36

1 Answers1

3

It seems like this function should take an int number of seconds, then resolve that into hrs + mins + secs.

#include <iostream>
using namespace std;

void Convert(int value, int &hour, int &minute, int &seconds)
{
    hour = value / 3600;           // Hour component
    minute = (value % 3600) / 60;  // Minute component
    seconds = value % 60;          // Second component
}

int main()
{
    int hour;
    int seconds;
    int minute;
    int Seconds_To_Convert = 5432;

    //calling Convert function
    Convert(Seconds_To_Convert, hour, minute, seconds );

    //compute
    cout << hour <<" hours and " << minute << " minutes " << "and " << seconds << " seconds ";
    return 0;
}

Output

1 hours and 30 minutes and 32 seconds  

Working example

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218