I am trying to write a program that tells the difference between the two times the user inputs. I am not sure how to go about this. I get the errors :
Line 27|error: invalid operands of types ‘int’ and ‘const MyTime*’ to binary ‘operator-‘|
Line |39|error: cannot convert ‘MyTime’ to ‘const MyTime*’ for argument ‘1’ to ‘int DetermineElapsedTime(const MyTime*, const MyTime*)’|
I also need a lot of help in this problem. I don’t have a good curriculum, and my class textbook is like cliffnotes for programming. This will be my last class at this university. The C++ teztbook I use(my own not for class) is Sam’s C++ One hour a day.
#include <iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
struct MyTime { int hours, minutes, seconds; };
int DetermineElapsedTime(const MyTime *t1, const MyTime *t2);
long t1, t2;
int DetermineElapsedTime(const MyTime *t1, const MyTime *t2)
{
return((int)t2-t1);
}
int main(void)
{
char delim1, delim2;
MyTime tm, tm2;
cout << "Input two formats for the time. Separate each with a space. Ex: hr:min:sec\n";
cin >> tm.hours >> delim1 >> tm.minutes >> delim2 >> tm.seconds;
cin >> tm2.hours >> delim1 >> tm2.minutes >> delim2 >> tm2.seconds;
DetermineElapsedTime(tm, tm2);
return 0;
}
I have to fix the errors first. Anyone have any ideas??
Please take a look on your implementation of
DetermineElapsedTime.How the compiler should know what you mean with the line
You cannot simply subtract the two structures. You have to implement this by yourself.
EDIT:
Better you use
this is more C++ like.
I end up with (still ugly, but for the moment only the main problem is remaining)
You still need to find a solution for the subtraction of your data in your
MyTimestructure.