Hashmat the brave warrior

The link for the qstn:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=44&problem=996&mosmsg=Submission+received+with+ID+12917425

my code:
#include<iostream>

using namespace std;

int main()
{
int hashmatArmy, opponentArmy;


while(cin>>opponentArmy>>hashmatArmy)
{
if(hashmatArmy<opponentArmy)break;
else
cout<<(hashmatArmy-opponentArmy)<<endl;
}


return 0;
}

I submitted this problem in UVA, but it returned as wrong answer!!! I can't figure out where I went wrong, so please help me out :D
You should format your code properly, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>

using namespace std;

int main()
{
	int hashmatArmy, opponentArmy;

	while(cin>>opponentArmy>>hashmatArmy)
	{
		if(hashmatArmy<opponentArmy)break;
                else // this else isn't needed...
		cout<<(hashmatArmy-opponentArmy)<<endl;
	}

	return 0;
}


The question reads as if you need to use a file, but you've used the command line input, could that be the problem?

The code compiles and runs fine for me, do you need help with file io?
Last edited on
Funny I had just solved this question on UVA about 3 days ago. Your algorithm is correct to a point, but not quite because you have not understood the question. For example, there is supposed to be an output for every input you are given, so that break statement is not supposed to be there.

Hint: Absolute value
http://www.cplusplus.com/reference/cstdlib/labs/
I solved the problem after I posted this, so I did not bother to check this topic. Finally I checked it today, thanks guys anyway for the help.
Topic archived. No new replies allowed.