Apr-10-2020, 08:46 PM
Stared at this code for way too long before I saw the problem.
suma is set to 0 before entering the while loop. if the first iteration produces "two of hearts", "six of spades", "four of diamonds", "ace of spades", "jack of clubs", then suma will be 1 and the if clause will pass.
Now what happens on the second iteration? suppose the choices are "three of spades", "ten of hearts", "king of spades", "four of clubs", "nine of diamonds". Well, suma is still 1 from the previous iteration, so even though nothing is added, it will still be 1 in the if clause and it will pass again.
The solution? Put suma = 0 within the while loop, not outside of it.
suma is set to 0 before entering the while loop. if the first iteration produces "two of hearts", "six of spades", "four of diamonds", "ace of spades", "jack of clubs", then suma will be 1 and the if clause will pass.
Now what happens on the second iteration? suppose the choices are "three of spades", "ten of hearts", "king of spades", "four of clubs", "nine of diamonds". Well, suma is still 1 from the previous iteration, so even though nothing is added, it will still be 1 in the if clause and it will pass again.
The solution? Put suma = 0 within the while loop, not outside of it.