cpp_primer_plus/ch03/04.cpp

18 lines
646 B
C++
Raw Normal View History

2022-08-24 05:44:15 +08:00
# include <iostream>
# include <cmath>
using namespace std;
long convt = 60;
long convd = 24;
int main(){
long time_all;
cout << "Enter the number of seconds: ";
cin >> time_all;
int day, hour, minute, second;
day = time_all / pow(convt,2) / convd;
hour = (time_all - day * pow(convt,2) * convd)/ pow(convt,2);
minute = (time_all - day * pow(convt,2) * convd - hour * pow(convt,2)) / pow (convt,1);
second = time_all - day * pow(convt,2) * convd - hour * pow(convt,2) - minute * pow (convt,1);
cout << time_all << " secods = " << day << " days, " << hour << " hours, " << minute << " minutes, " << second << " seoncds\n";
return 0;
}