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

Where is my mistake?Tell me please.C++.
Posted by Mihran Muradyan (Fizmat) 7 May 2009 17:19
#include"iostream.h"
double S,n;
int main()
{
    cin>>n;
    if(n==0)S=1;
    if(n>0)S=(n+1)*n/2;
    if(n<0)
    {
        n=n*(-1)+2;    S=(3-n)*n/2;
    }
    cout<<S<<endl;
    return 0;
}
Re: Where is my mistake?Tell me please.C++.
Posted by zdw1224 11 May 2011 19:50
using namespace std;
Re: Where is my mistake?Tell me please.C++.
Posted by lihaitao 18 May 2011 19:57
#include<iostream>
using namespace std;
int S,n;
int main()
{
    cin>>n;
    if(n==0)S=1;
    if(n>0)S=(n+1)*n/2;
    if(n<0)
    {
        n=n*(-1)+2;    S=(3-n)*n/2;
    }
    cout<<S<<endl;
    return 0;
}

The codes above are my correct codes modified from your codes.
There are three mistakes you made:
1.#include"iostream.h" should be #include<iostream>.
2.If you want to use the "cin", you should define namespace "std".
3.S and n should be defined as "int" ,not "double".