• + 0 comments

    public static int howManyGames(int p, int d, int m, int s) { // Return the number of games you can buy

        int n=0;        
    
        while(s-p>=0)
        {            
            n++;
            s-=p;            
            p-=d;
    
            if(p<=m)
            {
                p=m;
            }      
        }
    
        return n;
    }