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

×

ATM problem C++ help

I have submitted by code 3 times but codechef still says my answer is wrong, I have tested it multiple times and I cannot seem to find whats wrong, if someone could point this out it would really help me:

const double fee = 0.50;
double balance = 0;
int withdraw_amount = 0;




int main()
{
cin >> withdraw_amount >> balance;

if (withdraw_amount % 5 != 0)
    {
        cout << balance << endl;
    }
else if (withdraw_amount > balance)
    {
        cout << balance << endl;
    }
else
    {
        balance -= withdraw_amount + fee;
        cout << setprecision(2) << fixed << balance << endl;
    }



return 0;
}

asked 10 Nov '14, 06:29

az3az09_3134's gravatar image

0★az3az09_3134
111
accept rate: 0%


@az3az09_3134
Brother your code gives WA for test case

 30 30.25

link

answered 10 Nov '14, 07:54

rishabhprsd7's gravatar image

2★rishabhprsd7
1.9k11141
accept rate: 14%

you should use && operator to combine the the if and else if statement because here both the conditions need to be followed but not one amongst them.

link

answered 21 Nov '14, 15:25

gagan1998_oct's gravatar image

1★gagan1998_oct
1713
accept rate: 15%

use this code. i got my answer correct.

include <iostream>

include<iomanip>

using namespace std; int main() { float y; int x; cin>>x; cin>>y; if(x>=0&&x<=2000&&y>=0&&y<=2000) { if((x+0.50)<y&&x%5==0) y=y-x-0.50; }cout<<y; }

link
This answer is marked "community wiki".

answered 21 Nov '14, 15:33

namankumar's gravatar image

0★namankumar
2521621
accept rate: 0%

hope this will help you

(21 Nov '14, 15:35) namankumar0★
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:

×2,000
×1,767
×180
×177

question asked: 10 Nov '14, 06:29

question was seen: 2,988 times

last updated: 21 Nov '14, 15:35