What is wrong in my code, can anyone help?

#include <stdio.h>
int main(void)
{
    float initialamt;
    int deductamt =0;
// taking input of the account balance and money to be withdrawn 
    scanf("%f", &initialamt);
    scanf("%d", &deductamt);
// Checking if the mat is a multiple of 5 and less than act balance
    if(deductamt%5 ==0 && deductamt<= initialamt-0.50)
    {
        initialamt = initialamt - deductamt -0.50;
        printf("%2f", initialamt);
    }
    else
    {
        printf("%2f", initialamt);
    }
    return 0;
}

what error you are getting please specify

The code is working fine on my laptop but when I post it on CodeChef its saying wrong answer.

//let me take as initialamt = Y and deductamt = X

1.) Don’t initialize deductamt to 0, (range is starting from 0 which is the condition to the person having amount)
2.) Use to give brackets for one condition in if-else statements(in C).

//The code should be:
//calculate it by putting values
int main(void) {
	float Y;
	int X;
	scanf("%d %f",&X,&Y);
	if((X+0.5<=Y) && (X % 5==0))
	 Y=Y-(X+0.5);
	printf("%.2f",Y);
	return 0;
}
1 Like

Thank you

1 Like

it may not be passing tricky test cases . It happens many times . Check the solution which has been accepted may be it would help you.

okay