Self-learning the MQL5 language from scratch - page 41

 
MrBrooklin:

That's right! I have the time in days. And the training period and how many days have passed since I started. I guess I don't understand something.

Respectfully, Vladimir.

In terms of condition logic, the string "I will learn the language" can be output as a result of calculating the time and patience available to learn it. If one of the parameters (time or patience) equals zero, then the language cannot be learned. Therefore, there is a logical error in the condition.
 
MrBrooklin:

Thank you, Peter! I have already been helped to understand this issue.

I continue studying the MQL5 programming language and today I am pasting the code of a script, which is a continuation of one of the tasks from the participants of this thread. I tested the script in all modes. Everything works as it should. I have set the input parameters to a minimum to begin with.

Regards, Vladimir.

Do you do ... finish writing the Russian names in the names of variables and functions. This is considered very bad form. Clearly you're making programs for yourself, but this is not 1C after all. Get used to the standard codestyle at once. Then it will be easier for you to read other people's code from Expert Advisors and indicators, which you will definitely need.

 
Реter Konow:
In terms of condition logic, the string "I will learn the language" can be output as a result of calculating the time and patience available to learn it. If one of the parameters (time or patience) equals zero, you won't be able to learn the language. Therefore, there is a logical error in the condition.

Do you mean a logical error in the condition of the function itself or in the operation of the script?

Regards, Vladimir.

 
Vasiliy Sokolov:

You should... stop writing Russian names in the names of variables and functions. This is considered very bad form. I understand that you are making programs for yourself, but it's not 1C after all. Get used to the standard codestyle at once. Then it will be easier for you to read other people's code of Expert Advisors and indicators, which you will definitely need.

Vasily, you won't believe it, but I'm all for it! It's just the condition of the task has been given in Russian, hence the continuation. I will definitely rewrite the script using English.

Regards, Vladimir.

 
MrBrooklin:

Do you mean a logical error in the condition of the function itself or in the operation of the script?

Respectfully, Vladimir.

There are no syntax errors in the code, but the logic is broken, and you have to watch it closely.

The calculation itself in the sufficiency_time function is illogical. Time is sufficient when it is not equal to zero. The function calculates the time difference and returns a boolean yes/no. That is, the function is not structured correctly. Revisit the calculation of sufficiency_time().

Although, no. The function returns ushort, but there's still no logic. Sufficiency_time should be greater than zero.
 
Реter Konow:
There are no syntax errors in the code, but the logic is broken, and you have to watch it closely.

The calculation itself in the sufficiency_time function is illogical. Time is sufficient when it is not zero. The function calculates the time difference and returns a logical yes/no. That is, the function is not structured correctly. Recalculate sufficiency_time().

Although, no. The function returns ushort, but there's still no logic. The sufficiency_time should be greater than zero.

It's clear now, just need to figure out how to do it. It will be something to do at the weekend.

Regards, Vladimir.

 
Реter Konow:
There are no syntax errors in the code, but the logic is broken, and you have to watch it carefully.

The calculation itself in the sufficiency_time function is illogical. Time is sufficient when it is not zero. The function calculates the time difference, but returns a logical yes/no. That is, the function is not structured correctly. Revisit the calculation of sufficiency_time().

Although, no. The function returns ushort, but there's still no logic. Sufficiency_time should be greater than zero.

If you're writing for beginners, write in plain language, there's nothing to go into from afar, to belittle.

and your threats will see where they may be of interest
 

I continue studying the MQL5 programming language and am posting the code of a script, which is a continuation of one task from the participants of this thread. The script has been tested in all modes. No problems were detected. Applied the minimum number of input parameters to start with. The script code is written in English, the comments to the code are in Russian, to ease the learning process. As I promised earlier, I tried to describe the script in a manner comprehensible to a pupil of the 1-st form of programming school.

Best regards, Vladimir.

//+------------------------------------------------------------------+
//|                                                Learning_MQL5.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "Copyright 2020, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property description "Скрипт подводит итог обучения языку программирования MQL5. В зависимости от "
#property description "входных параметров печатает во вкладке \"Эксперт\" торгового терминала два"
#property description "сообщения на русском языке: \"Я выучу язык MQL5!\" или \"Я не выучу язык MQL5!\""
#property description "Код скрипта написан на основе примера, приведенного Valeriy Yastremskiy на сайте"
#property description "MQL5, в теме \"Самообучение языку MQL5 с полного нуля\"." 
#property description "======================================================"
#property description "Ссылка на пример https://www.mql5.com/ru/forum/352460/page30#comment_18646826"
//---
#property version     "1.00"              //версия скрипта 1.00
//---
#property script_show_inputs              //выводить окно со свойствами перед запуском скрипта 
//--- Зададим входные параметры скрипта: 
input ushort Period_learning=500;         //Полный период обучения в днях
input ushort Days_passed=10;              //Сколько дней прошло с начала обучения
input bool   Patience=true;               //Терпение (true - достаточно; false - не достаточно)
//--- Зададим глобальные переменные:
//переменная enough_time (достаточно времени), где ushort - минимальное значение "0", максимальное "65535"
ushort enough_time;
//переменная enough_patience (достаточно терпения), где bool - логическое значение: истина (true) или ложь (false)
bool enough_patience;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() //старт работы скрипта
  {
/* Зададим условие для работы скрипта. Если:
   1. значение функции "имею время" будет больше или равно "Полного периода обучения", заданного 
      во входных параметрах скрипта;
   2. и значение функции "имею время" не будет равно нулю;
   3. и значение функции "имею терпение" будет равно значению истина (true)
*/
   if(have_time()>=Period_learning && have_time()!=0 && have_patience()==true)
     {
      Print("Я выучу язык MQL5!");    //выводим сообщение "Я выучу язык MQL5!"
     }
   else //в противном случае
     {
      Print("Я не выучу язык MQL5!"); //выводим сообщение "Я не выучу язык MQL5!"
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//--- Функция "имею_время"
ushort have_time()            //создаём функцию "имею_время" и присвоим тип данных ushort
  {
   enough_time=Days_passed;   //задаём для значения enough_time (достаточно времени) значение равное
                              //входному параметру "Сколько дней прошло с начала обучения" (Days_passed)

   return(enough_time);       //возвращаем значение "достаточно времени" в функцию "имею время"
  }
//--- Функция "имею_терпение"
bool have_patience()          //создаём функцию "имею_терпение" и присвоим тип данных bool
  {
   enough_patience=Patience;  //задаём для переменной enough_patience (достаточно терпения) значение равное
                              //входному параметру "Терпение" (Patience): истина или ложь

   return(enough_patience);   //возвращаем значение "достаточно терпения" в функцию "имею терпение"
  }
//+------------------------------------------------------------------+
 

First, learn how to work with string variables from Dmitry Fedoseyev, infostringements are very foggy at the stage of studying other people's code,

In the article he reviewed, everything is clear, and you'll learn a lot of things at the same time, I'm speaking as a reader of most articles here, I think no one has read more than me)

 
MrBrooklin:

That's right! I have the time in days. And the training period and how many days have passed since I started. I guess I don't understand something yet.

Regards, Vladimir.



Your code and logic are correct. On my IMHO, I looked yesterday, at first I was surprised myself, but then I caught the difference... :-)