runtime error in codeblocks and ideone

i have experienced many times that a certain program runs well in code blocks but give runtime error in ideone. Is it due to some optimizations by the compiler?? How to turn them off?

1 Like

similar problem with this code also
#include
#include <stdlib.h>

using namespace std;
int calculate(int year);
int leap(int y);
int main()
{int i,j,num,year,arr[100];
cin>>num;

for (i=1;i<=num;i++){
cin>>arr[i];
}
for (j=1;j<=num;j++){
calculate(arr[j]);

}

}
int calculate(int year)
{int no;

no=year-2001;
no=abs(no);
no=no+leap(year);

if(no%7==0){cout<<“Monday\n”;}
else if(no%7==1){cout<<“tuesday\n”;}
else if(no%7==2){cout<<“wednesday\n”;}
else if(no%7==3){cout<<“thursday\n”;}
else if(no%7==4){cout<<“friday\n”;}
else if(no%7==5){cout<<“saturday\n”;}
else if(no%7==6){cout<<“sunday\n”;}
}
int leap(int y){
int error=0;
if(y>2001){
for(int i=y;i>2001;i–){
if(i%4==0){
if(i%100==0){ if(i%400==0){error++;}
else {break;} }

             else if(i%100!=0){error++;}

            }
    }
}
else if(y<2001){
    for(int i=y;i<2001;i++){
            if(i%4==0){
                    if(i%100==0){ if(i%400==0){error++;}  }




             else if(i%100!=0){error++;}

            }
    }
}

else if (y=2001){error++;}
return error-1;
}

are you asking about turning off the optimizations of code blocks or ideone ?

Give situations (elaboration with code) where this is happening.

Maybe you are supplying optimization flags to your local compiler used by code::blocks.

2 Likes

what i meant was that the code::blocks compiler is not showing runtime error but ideone is showing so for the same test cases.

see this question which was answered by @mediocoder

http://discuss.codechef.com/questions/67011/transform-the-expression

(for eg:- if you don’t terminate a string with ‘\0’ and print it then it will show run time error in ideone but will perfectly work in code::blocks
as it was the case in above link)