C++转换分秒
C++ to convert minutes and seconds
我有一个 C++ 代码来转换秒和分钟,但似乎无论何时转换秒,它都不会更新分钟。我该如何解决?
#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;
}
谢谢
这个函数似乎需要 int
秒,然后将其解析为小时 + 分钟 + 秒。
#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;
}
输出
1 hours and 30 minutes and 32 seconds
我有一个 C++ 代码来转换秒和分钟,但似乎无论何时转换秒,它都不会更新分钟。我该如何解决?
#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;
}
谢谢
这个函数似乎需要 int
秒,然后将其解析为小时 + 分钟 + 秒。
#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;
}
输出
1 hours and 30 minutes and 32 seconds