I am working on football about my C ++ assignment and I had to face a problem with the map .
The problem I have encountered me is that when I store 2 or more "midfielders" as a key, even the cot data looks different, but when I second -> On the second value, I multiply, first -> second "adds" value and multiply with it.
Example
John Midfielder 1 Steven Midfielder 3
I have a program that already reads the position of the player. So the map goes in such a way:
John 1 (key, value) Steven 3 (key, value) if (player's name == A-> First & amp; amp; ; Player designation == "midfielder") {Cout & lt; & Lt; A-> Second * 2000 & lt; & Lt; Endl; // target = $ 2000}
Then properly, the program should output:
2000 6000
< P>> But instead, I'm getting 2000 8000
So, I'm assuming that it adds 1 to 3 (as a result 4 ) And multiplied with 2000, which is completely wrong ...
I tried cout a-> before and one-> seconds and found me:
<1> John 1 Steven 3
But after the multiplication, it is completely different. any idea?
Thank you.
EDIT: OK, I try. I'm actually calculating the bonus for each status area. I've already put field data in the map and here is the actual code.
multiset & lt; String, lower & lt; String & gt; & Gt; :: Iterator q, p = myset.begin (); Q = myset.begin () ++; While (p! = Myset.end ()) {if (* p == * q) {currentScore = (int) myset.count (* p); Mymap.insert (pair (* p, current session)); } Else if (* p! = * Q & topscore == 0) {topScore = (int) myset.count (* q); TopScorer = * q; Mymap.insert (pair (* q, topScore)); } And if (* p! = * Q) {currentScore = (int) myset.count (* p); Mymap.insert (pair (* p, current session)); If (current session & gt; topsaurus) {topScore = currentScore; TopScorer = * p; Mymap.insert (pair (* P, topscore)); }} P ++; } Map & lt; String, int & gt; :: iterator a = mymap.begin (); While (a! = Mymap.end ()) {if (playerName == a-> first and & amp; amp; amp; player; == "goalkeeper") {goalkeeper ++; GoalkeeperBonus + = (to be & gt; second * 5000); SumBonus + = goalkeeperBonus; } And if (player name == A-> first and player designation == "midfielder") {midfolder ++; MidfielderBonus + = (to be & gt; second * 2000); SumBonus + = midfielderBonus; } A ++; Test Data is: Score: 3-1 Ben Steven Ben Score: 2-0 John Steven Score: 1-0 Ben Score: 0-0 Score: 1-1 Coal Score: 1- 2 Ben score: 3-0 Cole Steven Ben I tried to coat during the loop and I got the output: <
It was Steven's Should have the right output with 3 goals. But I'm getting 4, which has been associated with John. Is there a way to assign such a bonus - which is the name of the first player?
midfielderbones = = (a-> second * 2000);
That's why + = means that it will accumulate data. I believe that you forget the player midfielder bonus = 0
when you go to the next player does not show the initialization of hard bonus variables to tell you as a included code snippet.
Comments
Post a Comment