ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

I can't get Accepted and I can't my mistake ,help me please
Posted by azadeh 3 Jul 2006 11:01
do you khonw why my program is wrong?
#include<iostream>
using namespace std;
main(){
    long int n;
    cin>>n;
    if(n<0){
        n=-n;
        n=n*(n+1)/2;
        n=-n+1;
    }
    if(n==0)
        n=1;
    if(n>0)
        n=n*(n+1)/2;
    cout<<n;

}
Re: I can't get Accepted and I can't my mistake ,help me please
Posted by KAV 3 Jul 2006 11:09
if(n<0)
   ...
ELSE if( n == 0 )
   ...
ELSE if( n > 0 )
   ...
You missed "else". Without it program works wrong, of course.