classtime
{
privateinthour,minute,second;
}
privatetimeadd(timet1,timet2)
inttemp;
timet3;
t3.second=t1.second+t2.second;
temp=t3.second/60;
if(temp>0)
t3.second=t3.second%60;
t3.minute=t1.minute+t2.minute+temp;
temp=t3.minute/60;
t3.minute=t3.minute%60;
t3.hour=t1.hour+t2.hour+temp;
temp=t3.hour/24;
t3.hour=t3.hour%24;
returnt3;
你在哪裡執行的啊?另外根據題意add僅僅是個方法,沒有在任何類裡面,或者你把方法寫進time類裡試試
classtime
{
privateinthour,minute,second;
}
privatetimeadd(timet1,timet2)
{
inttemp;
timet3;
t3.second=t1.second+t2.second;
temp=t3.second/60;
if(temp>0)
t3.second=t3.second%60;
t3.minute=t1.minute+t2.minute+temp;
temp=t3.minute/60;
if(temp>0)
t3.minute=t3.minute%60;
t3.hour=t1.hour+t2.hour+temp;
temp=t3.hour/24;
if(temp>0)
t3.hour=t3.hour%24;
returnt3;
}
你在哪裡執行的啊?另外根據題意add僅僅是個方法,沒有在任何類裡面,或者你把方法寫進time類裡試試