1
I can’t think of the mathematical logic of the following issue:
Three friends played the lottery. In case they win, the prize must be apportioned in proportion to the amount each gave for the realization of the bet.
The goal is to make a program that reads the amount each bettor invested and the value of the prize and at the end, inform how much each bettor would win from the prize based on the amount invested.
For ease I have only the draft of the pseudocode.
float aposta1, aposta2, aposta3, premio, recebe1, recebe2, recebe3;
leia aposta1, aposta2, aposta3, premio;
The great difficulty for me is that there is no predefined range of values for betting, thus making it difficult to create the algorithm.
In the algorithm I should instead use very basic content of programming, if possible even without conditional.
If you take how much corresponds in percentage of each bet and at the end, the prize be based on the same percentage, resolves?
– David Dias
total bet = (bet 1 + bet 2 + bet 3); bet 1 is how many percent of (bet total); bet 2 is how many percent of (bet total); bet 3 is how many percent of (bet total); receive 1 = %bet 1 on the prize; receive 2=%bet 2 on the prize; receive 3=%bet 3 on the prize; I made a PHP to test the logic https://ideone.com/MR4Me4
– user60252
Exact @Leocaracciolo. That’s the easy way to do it. Something I wasn’t even able to think about at that moment kkkk. Anyway, in the code you made, you used rule three to find the percentage of each bet, just a little different from what I thought just now, but that, anyway, comes if the problem described is solved. Thank you!!!
– Misael