Help me in solving the weightBL and tell me why this code is wrong. Thanks for your help

My issue

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int test, initial, final, s_fin, months, s_init;
	cin>>test;
	while(test--){
	    cin>>initial>>final>>s_init>>s_fin>>months;
	    int gain= final-initial;
	    int rate=gain/months;
	    if(rate>s_init && rate<s_fin){
	        cout<<1<<endl;
	    }else if(rate==s_init ||rate==s_fin){
	        cout<<1<<endl;
	    }else{
	        cout<<0<<endl;
	    }
	    
	}
	return 0;
}

Problem Link: CodeChef: Practical coding for everyone

@timtech1234
for 1 6 1 2 2
your code will print 1 but answer would be 0 cozz its increase per month will be 2.5 which is not in the range for 1-2 .

Wow your advice worked brilliantly well. I made the necessary adjustments on your word and it did work. Thanks so much.

1 Like