IShatrov / Quadratic-Equation-Solver

Quadratic Equation Solver
0 stars 0 forks source link

Nested ifs #17

Open derzhavin3016 opened 2 years ago

derzhavin3016 commented 2 years ago

https://github.com/IShatrov/Quadratic-Equation-Solver/blob/c1f2bdf52e6d4e7e3d05b1fd920b4025e129fd08/quadratic_equation_solver/main.cpp#L81-L103

I think that you can make this code look much simpler if you do like this (pseudocode):

if (a == 0)
  return solve_linear();

// solve real quadric

The main point here is that you can omit else clause if you have a return in corresponding if. So if you have a construction:

if (!something)
{
  // perform some actions
}
else
  return 0;

You can rewrite it:

if (something)
  return 0;

// perform some actions

Looks much simpler, isn't it?