Function not working well

 
Hello Everyone,
I hope you are all well, I was trying to create a function on MQL4 that
would tell me what day of the week is and this is what I came up with:
Sadly, it only returns Monday even if I feed it the day because I am
was going to use it with the function DayofWeek(). If anyone knows why
it doesn't work I will be very grateful

string DofW(int day)
{
   string DOW;
   if (day = 1)
   {
      return DOW = "Monday";
   }
   if (day = 2)
   {
      return DOW = "Tuesday";
   }
   if (day = 3)
   {
      return DOW = "Wednesday";
   }
   if (day = 4)
   {
      return DOW = "Thursday";
   }
   if (day = 5)
   {
      return DOW = "Friday";
   }
   if (day = 6)
   {
      return DOW = "Saturday";
   }
   if (day = 0)
   {
      return DOW = "Sunday";
   }
   else
   {
      return DOW = "Impossible";
   }
 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. if (day = 1)

    This is not a comparison, it is an assignment, and non-zero means true, thus you always get Monday.

  3. Not compiled, not tested, just typed.
    string DofW(int day){
      static string dowCap[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
      return dowCap[day];
    } 
    Not compiled, not tested, just typed.
  4. If you don't care about the capitalization, you can just use:

    string DofW(int day){
       return DofW(ENUM_DAY_OF_WEEK(day));
    }
    string DofW(ENUM_DAY_OF_WEEK day){
      return EnumToString(day);   // SUNDAY
    } 
 

Untested/uncompiled! Serves only as example:

string DayOfWeek( int nDay )
{
   static const string sDayOfWeek[] = {
      "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
      
   return
      ( nDay < 0 ) || ( nDay > 7 ) ? "undefined" : sDayOfWeek[ nDay ];
};
EDIT: Seems William was faster than me to give an answer while I was still typing.
 
Fernando Carreiro #:

Untested/uncompiled! Serves only as example:

EDIT: Seems William was faster than me to give an answer while I was still typing.

William is very good with copy and paste

 
Thank you very much to all, next time I will follow the guidelines Thanks
Reason: