below in this code i am just incrementing the value of i and checking if %age value of i w.r.t x is an absolute number i.e its decimal part is zero.
int x=(time[0]-48)*10*60*60+(time[1]-48)*60*60+(time[3]-48)*10*60+(time[4]-48)*60+(time[6]-48)*10+(time[7]-48);
cout<<x;
float temp;
int count=0;
for(float i=1;i<x;i++){
temp=(i/x)*100;
cout<<temp<<" ";
if(temp-(int)(temp)==0) count++;
}
return count;
but when i remove the command(cout<<temp<<" ";) this programme fails in system test.please help as i m totally confused as cout is not changing ne variables's value.
foe eg when x=1800 the correct answer is 99 but when i remove that line this prog. gives 92 as answer.
yeah its working that way.now can you tell me whats going on.do this type of declaration of temp force it to reside on memory rather than on FPU?
do i need to declare float every time in this way?
volatile forces the compiler to update the memory location as soon as possible, in this case by pulling it from the FPU (supposedly).
The problem is that your logic is depending on temp having a very specific precision. I would look to change that if to something like temp-int(temp)<epsilon. 'epsilon' being a very small value. Another option would be to use fixed point arithmetic.