0

Help me in c++

how can i fix the error #include <iostream> using namespace std; struct time{ int hour, minute, second; }; time computeTimeDifference(time t1, time t2){ return t1 - t2; } int main(){ time TIMEDIFFERENCE, T1, T2; cout << "Enter hours, minutes and seconds respectively:\n"; cin>> T1.hour >> T1.minute >>T1.second; cout <<"Enter stop time"; cout << "Enter hours, minutes and seconds respectively:\n"; cin>> T2.hour >> T2.minute >>T2.second; TIMEDIFFERENCE computeTimeDifference(T1, T2);

6th Mar 2022, 11:17 AM
Dee
Dee - avatar
6 Answers
+ 2
What do you expect from t1-t2 statement inside computeTimeDifference function? And you think that compiler know that?
6th Mar 2022, 11:29 AM
KrOW
KrOW - avatar
+ 1
Then, time is a name of a function which iostream include... Use another name... Futhermore you defined a structure and you expect that compiler know how do subtraction between 2 objects of this struct and is not true. You have to define a function that do the subtraction and return it
6th Mar 2022, 11:45 AM
KrOW
KrOW - avatar
+ 1
You are welcome.. Anyway i suggest 2 things: first, read always compiler error output and second, when post some code here, use code bits so is more easy help
6th Mar 2022, 11:50 AM
KrOW
KrOW - avatar
0
this is the rest of the code cout<<"TIME DIFFERENCE:" <<T1.hour<<":"<<T1.minute<<":"<<T1.second; cout << " - " << T2.hour<<":"<<T2.minute <<":"<<T2.second; cout << " = "<< TIMEDIFFERENCE.hour <<":" <<TIMEDIFFERENCE.minute <<":"<<TIMEDIFFERENCE.second; return 0; }
6th Mar 2022, 11:18 AM
Dee
Dee - avatar
0
where should i put it ?
6th Mar 2022, 11:32 AM
Dee
Dee - avatar
0
ok thank you
6th Mar 2022, 11:47 AM
Dee
Dee - avatar