Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8816057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:31:41+00:00 2026-06-14T04:31:41+00:00

I am trying to write a program that tells the difference between the two

  • 0

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??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:31:43+00:00Added an answer on June 14, 2026 at 4:31 am

    Please take a look on your implementation of DetermineElapsedTime.

    struct MyTime { int hours, minutes, seconds; };
    
    ...
    
    int DetermineElapsedTime(const MyTime *t1, const MyTime *t2)
    {
        return((int)t2-t1);
    }
    

    How the compiler should know what you mean with the line

        return((int)t2-t1);
    

    You cannot simply subtract the two structures. You have to implement this by yourself.

    EDIT:

    Better you use

    int DetermineElapsedTime(MyTime &t1, MyTime &t2)
    

    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 MyTime structure.

    #include <iostream>
    #include<cstdlib>
    #include<cstring>
    
    using namespace std;
    struct MyTime { int hours, minutes, seconds; };
    
    
    int DetermineElapsedTime(MyTime &t1, MyTime &t2)
    {
        // TODO: This is not correct! Implement the correct way.
        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;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a program that displays the integers between 1 and
I am trying to write a program that tells you whether a number is
I am trying to write a program that asks a user for a ten
I'm trying to write a simple high-low program that will output like this: $
Hello I am trying to write a program in python that asks the user
In a program that I'm trying to write now I take two columns of
I'm trying to write a program that would convert celcius to fahrenheit and visa-versa.
I am trying to write a program that will prompt you to enter someone's
I am trying to write a program that sends basic text files from one
I am trying to write a program that allows a binary to be run,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.