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++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 有没有简单的方法可以将"02:00"转换为分钟,比如 120?
- 将秒转换为小时、分钟、秒.百分之一秒
- 以C++为单位将毫秒转换为小时:分钟:秒:毫秒
- 将时间转换为小时、分钟和秒
- 如何在将秒转换为分钟且余数小于 10 秒时包含前导零
- 将几秒钟转换为几天,小时,分钟,秒格式(C )
- 将几秒钟转换为小时数分钟的公式是什么?
- 将年龄在几年,小时,几分钟和秒的时间内转换
- 将时间转换为分钟和秒
- C++转换分钟和秒
- 将十进制时间转换为小时和分钟,以便以C++显示
- 将秒转换为小时以及分钟和秒