Jump to content
  • Advertisement
Sign in to follow this  
OneThreeThreeSeven

Codechef not accepting my code O_o

This topic is 3194 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm doing this problem here http://www.codechef.com/problems/HS08TEST It shows as a wrong answer on code chef...but I have no idea why.
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	int wd;
	double bal;
	
	cin >> wd;
	cin >> bal;

	if ( wd % 5 != 0 )
	{
		cout << setprecision (2) << fixed << bal;
	}
	else if ( wd == bal )
	{
		cout << setprecision (2) << fixed << bal;
	}
	else if ( wd > bal )
	{
		cout << setprecision (2) << fixed << bal;
	}
	else if ( wd < bal )
	{
		wd = bal - wd;
		wd = wd - 0.50;
		cout << setprecision (2) << fixed << (double) wd + 0.50;
	}


	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
You need only 3 if statements. One for successful attempt, one for not being % 5,
and the last one for insufficient funds.

So here is the skeleton :

unsigned int get = 0;
float balance = 0.0f;
while( cin >> get >> balance )
{
if not % 5 print balance break;
else if get > balance - 0.5f print balance break; (what Storyyeller was talking about)
else if sucessful print balance - get - 0.5 with fixed 2-point precision break;

}

Share this post


Link to post
Share on other sites
Or no if statements at all:


#include <iostream>
#include <iomanip>

int main( int, char*[] ) {
int withdraw;
float balance;
std::cout
<< std::fixed << std::setprecision( 2 )
<< ( ( ( std::cin >> withdraw >> balance )
&& !(withdraw % 5)
&& withdraw + 0.5 <= balance )
? balance - withdraw - 0.5
: balance
) << '\n';
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!