Compilation Error ???
I recieve Compilation Error when submitting this code: (It
compiles fine on my compiler)?????
#include <iostream.h>
int main() {
int grupi[101] ;
int k, num ;
int sum=0 ;
cin >> k ;
for (int i=0; i<k; i++) {
cin >> num ;
if (num==0) grupi[i]=10000 ;
else grupi[i]=num/2 + 1 ;
}
for (i=1; i<k; i++)
for (int j=k-1; j>=i; j--)
if (grupi[j-1] > grupi[j]) {
int Temp=grupi[j-1];
grupi[j-1] = grupi[j] ;
grupi[j] = Temp ;
}
for (i=0; i<(k/2+1); i++) sum+=grupi[i] ;
cout << sum ;
return 0 ;
}
Re: Compilation Error ???
Posted by
Flyer 27 Oct 2001 16:43
> I recieve Compilation Error when submitting this code:
(It
> compiles fine on my compiler)?????
>
> #include <iostream.h>
>
> int main() {
> int grupi[101] ;
> int k, num ;
> int sum=0 ;
>
> cin >> k ;
> for (int i=0; i<k; i++) {
> cin >> num ;
> if (num==0) grupi[i]=10000 ;
> else grupi[i]=num/2 + 1 ;
> }
>
> for (i=1; i<k; i++)
> for (int j=k-1; j>=i; j--)
> if (grupi[j-1] > grupi[j]) {
> int Temp=grupi[j-1];
> grupi[j-1] = grupi[j] ;
> grupi[j] = Temp ;
> }
>
> for (i=0; i<(k/2+1); i++) sum+=grupi[i] ;
> cout << sum ;
> return 0 ;
> }
>
У тебя i объявлена внутри цикла, их компилятор это не
понимает. Проси отсылать ответ на E-MAIL, там более
подробная информация.
Re: Compilation Error ???
Ok, which compilator the system uses?
> > I recieve Compilation Error when submitting this code:
> (It
> > compiles fine on my compiler)?????
> >
> > #include <iostream.h>
> >
> > int main() {
> > int grupi[101] ;
> > int k, num ;
> > int sum=0 ;
> >
> > cin >> k ;
> > for (int i=0; i<k; i++) {
> > cin >> num ;
> > if (num==0) grupi[i]=10000 ;
> > else grupi[i]=num/2 + 1 ;
> > }
> >
> > for (i=1; i<k; i++)
> > for (int j=k-1; j>=i; j--)
> > if (grupi[j-1] > grupi[j]) {
> > int Temp=grupi[j-1];
> > grupi[j-1] = grupi[j] ;
> > grupi[j] = Temp ;
> > }
> >
> > for (i=0; i<(k/2+1); i++) sum+=grupi[i] ;
> > cout << sum ;
> > return 0 ;
> > }
> >
> У тебя i объявлена внутри цикла, их компилятор это не
> понимает. Проси отсылать ответ на E-MAIL, там более
> подробная информация.
Re: Compilation Error ???
> Ok, which compilator the system uses?
> May be gcc (GNU C Compiler (Linux))
>
Re: Compilation Error ???
oh shit mine's the same
#include <iostream.h>
#include <stdlib.h>
#define K 101
void main()
{
int group_num,person_num[K],temp,m,minimal_quantity=0;
cin>>group_num;
for(int i=0;i<group_num;i++)
{
cin>>person_num[i];
if(person_num[i]%2==0||person_num<1)
exit(1);
if(person_num[i]>10001)
exit(1);
}
for(i=1;i<group_num;i++)
for(int j=0;j<group_num-i;j++)
if(person_num[j]>person_num[j+1])
{
temp=person_num[j+1];
person_num[j+1]=person_num[j];
person_num[j]=temp;
}
for(i=0;i<=group_num/2;i++)
{
if(person_num[i]==1)
m=1;
else
m=person_num[i]/2+1;
minimal_quantity+=m;
}
cout<<minimal_quantity<<endl;
}
Re: Compilation Error ???
I have the same type of Error. I would post the source but under rules it says not to post source code. It compiles fine on my system and I use gcc that comes with MinGW. The most recent stable version so it should be up to date.
Re: Compilation Error ???
Humm, that is very interesting. I got the error because I didn't add a newline character after the last line in my program. And I can't declear and array after the first "executable statement in block". Humm, I think they should update to a C99 standard compiler.
Re: Compilation Error ???
Maybe instead of
if(person_num[i]%2==0||person_num<1)
you should write
if(person_num[i]%2==0||person_num[i]<1)
Re: Compilation Error ???
Posted by
nikman 19 Aug 2004 19:57
for (int j=k-1; j>=i; j--) - error!!!
int j;
for (j=k-1; j>=i; j--) - right!!!
Re: Compilation Error ???
The library u`re using ...
This is how it should be written :
#include <iostream>
using namespace std;
int main() {
int grupi[101] ;
int k, num ;
int sum=0 ;
cin >> k ;
for (int i=0; i<k; i++) {
cin >> num ;
if (num==0) grupi[i]=10000 ;
else grupi[i]=num/2 + 1 ;
}
for (int i=1; i<k; i++) // int i !
for (int j=k-1; j>=i; j--)
if (grupi[j-1] > grupi[j]) {
int Temp=grupi[j-1];
grupi[j-1] = grupi[j] ;
grupi[j] = Temp ;
}
for (int i=0; i<(k/2+1); i++) sum+=grupi[i] ; // int i !
cout << sum ;
return 0 ;
}