By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Problem solving in C# Task - Four Factors in NBA

+4 votes

Little Spiridon is a big NBA fan. However, since he's very good with math and not very athletic, he doesn't dream of becoming an NBA superstar, but an NBA analyst instead. Spiro just finished reading the book “Basketball on Paper” by Dean Oliver and is now looking to understand how the Four Factors of winning basketball games work. Will you help little Spiridon - the NBA fan, become big Spiridon – the NBA analyst?

According to Dean Oliver, the four factors of winning basketball games, are Shooting, Turnovers, Rebounding and Free Throws. Each factor can be applied to both the team’s offense, and defense, which basically gives us eight factors, but we will be focusing on the Offense part only, for now.

The Shooting Factor is measured using Effective Field Goal Percentage (eFG%). The formula, by which the eFG% is calculated, is (Field Goals (FG) + 0.5 * 3-Point Field Goals (3P)) / Field Goals Attempted (FGA).

The Turnover Factor is measured using Turnover Percentage (TOV%). The formula for the offensive TOV% is Turnovers (TOV) / (FGA + 0.44 * Free Throw Attempts (FTA) + TOV).

The Rebounding Factor for offense is measured in Offensive Rebounding Percentage (ORB%) and the formula for it is Offensive Rebounds (ORB) / (ORB + Opponent Defensive Rebounds (Opp DRB)).

The Free Throw factor, or the Free Throw Percentage (FT%), is by far the easiest to calculate and the formula for it is Free Throws (FT) / FGA.

Your job is to write a program, which takes certain input parameters, calculates the four offensive factors, rounded to the third digit after the decimal sign, and then prints them on the console. Each factor should always be a positive number.


The input data should be read from the console. It consists of eight input values, each at a separate line:

  1. FG – Field Goals
  2. FGA – Field Goal Attempts
  3. 3P – 3-Point Field Goals
  4. TOV – Turnovers
  5. ORB – Offensive Rebounds
  6. Opp DRB – Opponent Defensive Rebounds
  7. FT – Free Throws
  8. FTA – Free Throw Attempts

The input data will always be valid and in the format described. There is no need to check it explicitly.


The output should be printed on the console and it should consist of four strings, each printed on a separate line in the following format:

  • eFG% {factor result}
  • TOV% {factor result}
  • ORB% {factor result}
  • FT% {factor result}

Look at the examples below, to get a better understanding of how the output should be structured.


  • All input parameters will be valid integers, in the range [1 ... 3,000,000,000 ].
  • Allowed working time for your program: 0.25 seconds.
  • Allowed memory: 16 MB.
asked in C# category by user eiorgert
edited by user golearnweb

1 Answer

+1 vote
Best answer

Here is my solution, mate:

using System;

class FourFactorsNBA
    static void Main()
        decimal fg = decimal.Parse(Console.ReadLine());//FG – Field Goals
        decimal fga = decimal.Parse(Console.ReadLine());//FGA – Field Goal Attempts
        decimal threep = decimal.Parse(Console.ReadLine());//3P – 3-Point Field Goals
        decimal tov = decimal.Parse(Console.ReadLine());//TOV – Turnovers
        decimal orb = decimal.Parse(Console.ReadLine());//ORB – Offensive Rebounds
        decimal oppdrb = decimal.Parse(Console.ReadLine());//Opp DRB – Opponent Defensive Rebounds
        decimal ft = decimal.Parse(Console.ReadLine());//FT – Free Throws
        decimal fta = decimal.Parse(Console.ReadLine());//FTA – Free Throw Attempts

        decimal efgResult = ((fg+ 0.5m * threep) / fga);//eFG%
        decimal tovResult = ((tov) / (fga + 0.44m * (fta) + tov));//TOV%
        decimal orbResult = ((orb) / (orb + (oppdrb))); //ORB%
        decimal ftResult = (ft / fga); //FT%

        Console.WriteLine("eFG% {0:F3}", efgResult);
        Console.WriteLine("TOV% {0:F3}", tovResult);
        Console.WriteLine("ORB% {0:F3}", orbResult);
        Console.WriteLine("FT% {0:F3}", ftResult);


answered by user hues
selected by user golearnweb