Please help me in SURVIVE

I tried to solve a question in the beginner level. The code for the problem statement is: SURVIVE in the practice beginner level.

The code worked fine for certain test cases. But I don’t know whats possibly wrong with my code. So I request to debug the code.

Thanks in Advance.

Code goes here

int main(void) {
	
	int N,K,S,T,cn,ca,tn,bn;
	
	//cn=chocolates needed (per week), ca=chocolates availble (per week)
	
	//tn=total no of chocoloates needed, bn=no of boxes needed 
	
	scanf("%d",&T);
	
	while(T--)
	{
	    ca=cn=bn=tn=0;
	    
	    scanf("%d%d%d",&N,&K,&S);
	    
	 //To evaluate weather the chocolates in the box will be sufficient if we buy them for 6 days (output case:-1)
	  
	    cn=7*K;
	    ca=6*N;
	
	    if(ca<cn)
	    {
	        printf("-1\n");
	    }
	 //To evaluate no of boxes   
	    else
	    {
	       tn=S*K;
	       bn=tn/N;
	       
	       if(tn%N==0)
	       {
	           printf("%d\n",bn);
	       }
	       else
	       {
	          bn=bn+1;
	          printf("%d\n",bn);
	       }
	    }
	}
	
	
	return 0;
}  

Your code fails for all cases where S\le 7, i.e. when we have to survive within that week itself. Thats because your requirement-

 cn=7*K;
ca=6*N;

is assuming that question will ask to survive more than 7 days.

Got it. Thank you. :slight_smile: