新手上路,请求帮助!
//这是一个把秒转化显示为天,小时,分钟,秒的过程.如何写其中的转化过程,要求用const#include <iostream>
const int HOUR_PER_DAY=24;
const int MINS_PER_HOUR=60;
const int SECS_PER_MINS=60;
int main()
{
using namespace std;
long seconds;
cout<<"Enter the number of seconds: ";
cin>>seconds;
int day=seconds/SECS_PER_MINS/MINS_PER_HOUR/HOUR_PER_DAY; //本人的是笨人的实现过程,请高手指点更好的转化过程
int hour=(seconds-day*24*60*60)/60/60; //这样写用const太长了,用了数字
int minute=(seconds-day*24*60*60-hour*60*60)/60;
int second=(seconds-day*24*60*60-hour*60*60-minute*60);
cout<<seconds<<" seconds = "
<<day<<" days,"
<<hour<<" hours,"
<<minute<<" minutes,"
<<second<<" seconds";
return 0;
}
[[it] 本帖最后由 tymstill 于 2008-2-26 15:19 编辑 [/it]]