please i have a probleme "print"

 

void OnTick()
  {
  double x;
  x=(1/3);

  Print("value =",x);
   }

the print value is 0. why????

 

It is the way typecasting works.

Try this:

void OnTick()
 {
  double x;
  x=(1/3.);

  Print("value =",x);
 }

You can read more about it here - https://docs.mql4.com/basis/types/casting

Typecasting - Data Types - Language Basics - MQL4 Reference
Typecasting - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Typecasting - Data Types - Language Basics - MQL4 Reference
 
honest_knave:

It is the way typecasting works.

Try this:

You can read more about it here - https://docs.mql4.com/basis/types/casting

thank you very much
 

can I have one more question please

void OnTick()
  {
char   c1=1,c2=3;
//--- First example
   double d2=c1/c2+0.3;
   Print("resultat = ",d2);

resultat = 0.3

why?

 

Division happens before addition... https://docs.mql4.com/basis/operations/rules

1/3 = 0

0 + 0.3 = 0.3

Try this:

void OnTick()
  {
   char   c1=1,c2=3;
   //--- First example
   double d2=c1/(c2+0.3);
   Print("resultat = ",d2);
  }
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
  • docs.mql4.com
Precedence Rules - Operations and Expressions - Language Basics - MQL4 Reference
 
honest_knave:

Division happens before addition... https://docs.mql4.com/basis/operations/rules

1/3 = 0

0 + 0.3 = 0.3

Try this:

yes I know the basic of math but I solved the prob

can you look please

void OnTick()
  {
   char   c1=1,c2=3;
   //--- First example
   double d2=c1/double(c2)+0.3);
   Print("resultat = ",d2);
  }

now resultat is 0.6333333333333

 

Your code doesn't compile... what answer are you expecting?

1/3. = 0.333

0.333 + 0.3 = 0.633


 
honest_knave:

Your code doesn't compile... what answer are you expecting?

1/3. = 0.333

0.333 + 0.3 = 0.633


sorry there is a false bracket


double d2=c1/double(c2)+0.3);

yes 0.633

 
georges sleimen:

sorry there is a false bracket


double d2=c1/double(c2)+0.3);

yes 0.633

It's not bracket, it's parenthesis or ...

Forum on trading, automated trading systems and testing trading strategies

Correct brackets/bracers {}

whroeder1, 2014.09.10 13:44


  1. ...
  2. Be aware of the different uses of the words brackets/braces
    CharacterUS EnglishUK EnglishIndia
    ()ParenthesesBraces, round brackets, curved brackets, oval brackets
    []BracketsSquare Brackets
    {}BracesCurly bracketsflower bracket
    <>Angle brackets (or chevrons)
  3. ...

 
Alain Verleyen:

It's not bracket, it's parenthesis or ...



 
honest_knave:

Reason: