#include <iostream>
struct Time{
int hour, minute;
double second;
};
#include <iostream>
#include "increment.h"
Time increment(Time& time, double sec);
double convertToSeconds (const Time& t);
Time makeTime(double sec);
using namespace::std;
int main(Time& time)
{
Time t;
double seconds;
cout<<"请输入时间"<<endl;
cin>>t.hour>>t.minute>>t.second;
cout<<"请输入需要增加的时间"<<endl;
cin>>seconds;
time = increment(t, seconds);
return 0;
}
double convertToSeconds (const Time& t)
{
int minutes = t.hour*60 + t.minute;
double seconds = minutes*60 + t.second;
return seconds;
}
Time makeTime(double sec)
{
Time time;
time.hour = int(sec/3600.0);
sec -= time.hour*3600;
time.minute = int(sec/60.0);
sec -= time.minute*60;
time.second = sec;
return time;
}
Time increment(Time& time, double sec)
{
double seconds = convertToSeconds(time) + sec;
Time t = makeTime(seconds);
return t;
}
这是代码,在运行的函数increment中给变量t赋值的时候是乱码,本人新手没有c币悬赏,求各位大神指导