# Calculating cyclomatic complexity/ mccab's number

``````if field is blank or in form
print "enter again"
else
if no credit and debit < 1000
print "less amount"
else
print "accessed"
end if
end if
``````

I'm very confused in calculating the cyclomatic complexity. For the above program, I get the answer as 3, as there are two conditions and V(G)=P+1=2+1=3. But the answer is incorrect.

• Don't bother. MCC (McCabe Cyclic Complexity) has been shown to be VERY strongly correlated with raw SLOC, when run against real code from one of the BIG repositories. (We're talking MILLIONS of SLOC here.) – John R. Strohm May 20 '17 at 3:39
• I also get 3 for the code shown. But why is that supposed to be wrong? Please explain. Also, the flowchart seems to be totally unrelated with the code, why are you showing it? – amon May 20 '17 at 5:18

Calculating McCabe is not as simple as counting `if` statements and adding one. You have to count the number of possible paths through your code.
• The first `if` contains an `or` so there are 3 ways that you can go through that leg, (either or both condition being true).
• The second `if` contains an `and` so there are 3 ways, (either or both condition being false), to go through the `else`