تابعی بنویسید که زمان را به صور ارگومان صحیح (ساعت دقیق ثانیه) از ورودی دریافت کند و تعداد ثانیه هایی را که از اخیرن ساعت ۱۲ گذشته است را برگرداند. با استفاده از این تابع مدت بین دو زمان را برحسب ثانیه محاسبه کنید. فرض کنید این زمان ها هر دو درون یک دوره ۱۲ ساعتی قرار دارند.
#include<iostream>
#include<conio.h>
using namespace std;
unsigned seconds(unsigned, unsigned, unsigned);
int main()
{
unsigned hours, minutes, secs, temp;
cout << "Enter the first time as three integers: ";
cin >> hours >> minutes >>secs;
temp = seconds(hours, minutes, secs);
cout << "Enter the second time as three integers: ";
cin >> hours >> minutes >> secs;
cout << "The difference between the time is "
<< seconds(hours, minutes, secs) - temp
<< " seconds" << endl;
getch();
return 0;
}
unsigned seconds(unsigned h, unsigned m, unsigned s)
{
return 3600 * (h >= 12 ? h - 12 : h) + 60 * m + s;
}