You are not logged in. Please login at www.codechef.com to post your questions!

×

Whats wrong with my ATM ?

1
1

well, I have tested all the examples mentioned in the problem description(which work all right on my computer using gcc 4.8.2) but when I upload and hit submit, it says running and then suddenly WRONG ANSWER with a cross, not sure whats wrong with my code, you may see it below:

#include <stdio.h>

int main(void)
{
    int amount; 
    float balance;
    scanf ("%i %f", &amount, &balance);
    float ans = balance;
    if (amount % 5 == 0 && amount < balance)
        {
         ans = balance - (amount + 0.50);
        }

    printf ("%.2f", ans);

return 0;
}

asked 09 Jul '14, 20:07

nibnalin's gravatar image

6★nibnalin
1611516
accept rate: 0%

edited 09 Jul '14, 20:12

Try this case 20 20.1

(09 Jul '14, 20:26) gautam943★

Well, how do i correct the error in this ?

(09 Jul '14, 20:35) nibnalin6★

Read the question again and check the if condition in your code.

(09 Jul '14, 20:38) gautam943★

You are checking for "amount < balance" Instead, you should check for: "amount + 0.5 < balance && amt%5==0" this is because the sum, along with the extra 0.50 is required to do the transaction.

link

answered 09 Jul '14, 20:36

shiva1k95_10's gravatar image

3★shiva1k95_10
116412
accept rate: 0%

The amount 0.50 is also to be deducted from the balance.
So, the condition amount < balance should be amount <= (balance-0.5)

link

answered 09 Jul '14, 20:36

pratku123's gravatar image

4★pratku123
1.8k4932
accept rate: 14%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×3,703
×1,470
×846
×538
×189

question asked: 09 Jul '14, 20:07

question was seen: 861 times

last updated: 09 Jul '14, 20:38