[Solved] ATM Problem Code: HS08TEST

My output is same as the required by the question. Also my logic is also same as I checked the answer video but on submission its showing wrong answer even on successful execution and correct output for all test cases.
MY CODE:

#include<stdio.h>
int main()
{
    float ib,t,fb;
    int x;
    scanf("%f",&t);
    while(t--)
    {
        scanf("%d,%f",&x,&ib);
        
        if(((x+0.50)<=ib)&&(x%5==0))
        {
            ib=ib-x;
            printf("\n%.2f",ib-0.50);
        }
        else
        {
            printf("\n%.2f",ib);
        }
    }
    return 0;
}

MY INPUT:

3
30,120.00
42,120.00
300,120.00

MY OUTPUT

89.50
120.00
120.00

Please help me to find my mistake in the code

1 Like

No it isn’t :slight_smile:

[simon@simon-laptop][12:03:38]
[~/devel/hackerrank/otherpeoples]>echo "30 120.00" | ./a.out

0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00
0.00[simon@simon-laptop][12:04:01]
[~/devel/hackerrank/otherpeoples]>

The format you are using for your custom inputs does not match that of the problem description :slight_smile:


When I wrote the code on code chef platform, this is what the output came. Thats why I raised this query. But yes now when I run it on vs code, its showing the same output as commented by you.
Kindly tell me why two different outputs are coming for the very same code and I will be very thankful if you help to correct my mistake.

I know but when I removed the comma in scanf, all the output was coming out to be 0.00. I don’t know why but the correct answer came when I inserted comma in between.

To be more explicit:

3
30,120.00
42,120.00
300,120.00

is not in the format described in the Problem Statement.

3
30 120.00
42 120.00
300 120.00

is not in the format described by the Problem Statement.

30 120.00

is in the format described by the Problem Statement.

1 Like

Ok, so I have to remove the option of test cases in the problem. Is it fine otherwise?

  • You’ll also need to remove the “,” in %d,%f
  • You’ll probably need to stop printing out a blank line at the beginning
1 Like

@ssjgz Thank you so much for your help. I removed the blank line from output and it got submitted.

1 Like

No need to take test cases. there is only one testcase. remove the while loop and you are good to go

output wrong

if u r using if else statement

This post was flagged by the community and is temporarily hidden.

I have made all the corrections and submitted it already. Thank you for your help.