請問這個代碼如何實現區分上午下午(24制換成12制)
#include <stdio.h>
int main()
{
? ? //定義變量
? ? int distance=12;
? ? int Time=8;
? ? float cost;
? ? if (Time>=23||Time<=5)
? ? {
? ? ? ? ? ? cost=14+2.3*1.2*distance;
? ? }
? ? else
? ? {
? ? ? ? cost=14+2.3*distance;
? ? }
? ? if (distance<=3)
? ? {
? ? ? ? cost=14;
? ? }
? ? if (Time>=12)
? ? {
? ? ? ? Time=Time-12;
? ? }
? ? printf("小明%d點上班要花%.2f元錢", Time, cost);
? ? return 0;
}
2019-01-01
{
?tm* pt;
?time_t t=time(0);
?pt=localtime(&t);
?if(pt->tm_hour<12)
?printf("現在是上午:%d:%d\n",pt->tm_hour,pt->tm_min);
?else
?printf("現在是下午:%d:%d\n",pt->tm_hour,pt->tm_min);
}