Need advice about pointers and time elapsed program. How to fix invalid operands and cannot convert errors?
        Posted  
        
            by 
                user1781382
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user1781382
        
        
        
        Published on 2012-11-12T04:57:32Z
        Indexed on 
            2012/11/12
            4:59 UTC
        
        
        Read the original article
        Hit count: 191
        
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??
© Stack Overflow or respective owner