Little problem calcutale percentage

To add comments, please log in or register
fly7680
741
fly7680  

I have a small problem with the operator "/" I have no compilation problems but this counters block me the strategy tester


// Global scope

int A=0;
int B=0;
int Total=0;
double Percent=0;

int start() 
{ // my code

 Percent= (A*100)/Total;
}
If not insert /Total code works otherwise no
Alexander Puzanov
38005
Alexander Puzanov  

Try /double(Total)

Victor Ziborov
2807
Victor Ziborov  
fly7680:

I have a small problem with the operator "/" I have no compilation problems but this counters block me the strategy tester


If not insert /Total code works otherwise no

If any number is divided by zero, then we get infinity. Therefore, you can not divide by zero. In this case, you always get an error.

nicholi shen
1899
nicholi shen  
Metaquotes, please implement try catch!
fly7680
741
fly7680  
Victor Ziborov:

If any number is divided by zero, then we get infinity. Therefore, you can not divide by zero. In this case, you always get an error.

Great, I was reasoning and in fact I solved adding an if ()


// Global scope

int A=0;
int B=0;
int Total=0;
double Percent=0;

int start() 
{ // my code

 if(Total>=1) Percent= (A*100)/Total;
}
Thanks to everyone for the answers !!!
To add comments, please log in or register