Help me in solving KITCHENTIME problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    int x,y;
	    cin>>x>>y;
	    cout<<x-y<<endl;
	}
	return 0;
}

Problem Link: KITCHENTIME Problem - CodeChef

In the given problem, we need to find the total amount of time chef has worked. We have x as his starting time and y being the ending time with the conditions that y>x (always) .

To get the time, we find the difference between ending time and starting time , denoted as (y-x) in the code.

#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    int x,y;
	    cin>>x>>y;
	    // cout<<x-y<<endl; [Mistake]
        cout<<y-x<<endl;
	}
	return 0;
}

You were trying to subtract initial time from final time. So, although the magnitude of value was correct, the answer you were getting was in negative.