My code is running fine but when I submit the code it gives wrong answer

Code is not giving any error.

#include <iostream>
#include <iomanip>
using namespace std;

int main() {
	// your code goes here
	int vdraw;
	float mbal;
	float cut = 0.50;
	float rem;
	std::cin >>vdraw>>mbal;
	
	
	float calc = vdraw % 5;
	
	if((vdraw < mbal) && (calc == 0))
	    {
	       rem = mbal - (vdraw + cut) ;
	       std::cout << std::fixed << std::setprecision(2) << rem;
	    }
	else
	{
	    std::cout << std::fixed << std::setprecision(2) << mbal;
	}
	
	return 0;
}

Try this test case

Input

100 100.2

Expected Output

100.2

Your Output

-0.30
1 Like

I have modified it according to your suggested test case, but still it is giving same status.

Provide the modified version of your code.

1 Like
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
	// your code goes here
	int vdraw;
	float mbal;
	float cut = 0.50;
	float rem;
	std::cin >>vdraw>>mbal;
	
/*on each transaction we have to cut 0.50$US therefore the main balance should 
contain money which the customer want to withdraw and + 0.50$US.*/

	float satisfy = vdraw + cut;   // to calculate the tax on each transaction
	
	float calc = vdraw % 5;
	
	if((satisfy < mbal) && (calc == 0))
	    {
	       rem = mbal - (vdraw + cut) ;
	       std::cout << std::fixed << std::setprecision(2) << rem;
	    }
	else
	{
	    std::cout << std::fixed << std::setprecision(2) << mbal;
	}
	return 0;
}

Consider this test case

Input

100 100.5

Expected Output

0

Your Output

100.50
1 Like

Thanks for your suggestions. I have successfully submitted solution code.