- Arrays and Bool - Stuck with solving issue in my code - page 2

 
Vladislav Boyko #:
I think your code might be simpler if you ditch the array.

This will make your code simpler and eliminate possible errors when working with a global array

 
Vladislav Boyko #:
void findPricesOfCrossovers(double &price0, double &price1, double &price2)
  {
   /*
   The purpose of this function is to assign crossover price values to the corresponding reference parameters:
   price0 = ...
   price1 = ...
   price2 = ...
   */
  }

If you try to implement this without breaking it into sub-functions, the code will be quite cumbersome.

It will be easy to make a mistake in such code and it will be difficult to debug such code. Including due to the fact that you need to break the loop when all 3 intersections are found.

Imagine that you still wrote this code in the form of a single loop. After which you want to change the number of intersections. It would be quite difficult to make such changes.

Personally, I'm too lazy to solve one complex problem. I would break it down into sub-problems and instead of solving one complex problem, I would solve several simple problems. It is easier to solve several simple problems than one complex one.


Here's a little hint.

This function will do the following:

  • find crossover #0
  • find crossover #1
  • find crossover #2

What can be “taken out of brackets” here?😄

“taken out of brackets” is an analogy with mathematics. Not sure if I translated this into English correctly