PHP (HELP ME SOLVE A PROPLEM PLEASE)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vagelism
Forum Newbie
Posts: 1
Joined: Sat Sep 06, 2008 1:01 am

PHP (HELP ME SOLVE A PROPLEM PLEASE)

Post by vagelism »

Hello to Everyone.

I have a little problem that I try to solve in PHP.
Suppose we have a shooting target which has three circles. The inner one is the most accurate and gives five points for each bullet there. The middle gives four points and the last one , the outer gives three points, we always try to shoot with ten bullets every time. So an example… 2 bullets at the center 1 in the middle and 2 at the outer gives us a result of. 2x5=10 1x4=4 and 2x3=6 total score is 5/20 (5 the total bullets in the target and 20 the actual score).
So I want some code that I will import the result and it will return me if this shooting score is possible. For example (5/26)is not possible since the maximum result is 5c5=25.
Thank you for your help.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: PHP (HELP ME SOLVE A PROPLEM PLEASE)

Post by greyhoundcode »

You could always try coding the solution yourself, it seems fairly straightforward ... but since I've just woken up and need to kickstart my brain, how about this, which tests against scores that are infeasibly high or low.

Code: Select all

function AssessScore($score)
{
    $score = explode("/",$score);
    
    $rounds = $score[0];
    $points = $score[1];
    
    $minPos = $rounds * 3;
    $maxPos = $rounds * 5;
    
    if (($points >= $minPos) && ($points <=$maxPos))
    {           
        return true;
    }
 
    return false;
}
Where the argument passed takes the form of a string "rounds_fired/total_score" so you would test against AssessScore("5/25")
Post Reply