我正在编写一个代码,它需要两个用户输入的时间并将它们全部切换为秒(使用该函数)给我经过的时间并将其存储在我的头文件中,然后写入屏幕已用时间为hh:mm:ss 。我在使用Time1的功能方面遇到了麻烦。和Time.2以及应该进入冒号的delim1和delim2。我遇到错误而无法运行它。我相信还有其他问题。我真的需要帮助我被困住了!非常感谢。 说我输入12:15:30作为开始时间和结束时间13:30:30它应该输出我经过的时间是1:15:00。 任何人都可以搞清楚吗?这听起来很基本,但我迷路了。我甚至无法读入数字。这是我的代码:更新应该编译。
#include <iostream>
#include <fstream>
#include "C1A7E1_MyTime.h"
using namespace std;
void DeterminedElapsedTime(const MyTime& Time1,
const MyTime& Time2,
double& ElapsedTimeAsSeconds);
int main()
{
char *delim1 = ":";
MyTime Time1;
MyTime Time2;
cout << "Input first clocktime and second clocktime (hh:mm:ss hh:mm:ss) \n";
cin >> Time1.hours >> delim1 >> Time1.minutes >> delim1 >> Time1.seconds;
cin >> Time2.hours >> delim1 >> Time2.minutes >> delim1 >> Time2.seconds;
// do validation of input, minutes and seconds 0 to 59
double ElapsedTimeAsSeconds = 0.0;
DeterminedElapsedTime(Time1, Time2, ElapsedTimeAsSeconds);
// need to do something with the answer - Convert to HH:MM:SS ?
return 0;
}
//function:
#include"C1A7E1_MyTime.h"
void DeterminedElapsedTime(const MyTime& Time1, const MyTime& Time2, double& ElapsedTimeAsSeconds)
{
double elapsedtime;
double Time1AsSeconds = Time1.hours * 3600 + Time1.minutes * 60 + Time1.seconds;
double Time2AsSeconds = Time2.hours * 3600 + Time2.minutes * 60 + Time2.seconds;
ElapsedTimeAsSeconds = Time1AsSeconds - Time2AsSeconds;
}
//header file
struct MyTime {unsigned int hours, minutes, seconds; };