×

# 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●11●41 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; }

This answer is marked "community wiki".

2521621
accept rate: 0%

(21 Nov '14, 15:35)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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