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

×

# ATM problem C++ help

 0 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 1●1●1 accept rate: 0%

 1 @az3az09_3134 Brother your code gives WA for test case  30 30.25 answered 10 Nov '14, 07:54 1.9k●1●12●43 accept rate: 14%
 1 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. answered 21 Nov '14, 15:25 171●3 accept rate: 15%

use this code. i got my answer correct.

# 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

2521624
accept rate: 0%

hope this will help you

(21 Nov '14, 15:35)
 0 using namespace std; int main() { int amt, bal ; cin>>amt; cin>>bal; if (amt % 5 == 0) {  bal = bal - amt - 0.5; cout<
 toggle preview community wiki:
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,471
×1,916
×200
×190

question asked: 10 Nov '14, 06:29

question was seen: 3,687 times

last updated: 06 Mar, 20:50