|
|
вернуться в форумWhere is my mistake?Tell me please.C++. #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++. using namespace std; Re: Where is my mistake?Tell me please.C++. #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". |
|
|