expected 'while' before main???

???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  int prime(int d){
int e=0;

do
{

for (int i=2;i<d;i++){

if (d%i==0){e=e;}
else{e+=1;}
d+=1;
cout<<e<<endl;

}
while(e!=20);
return e;
}

int main(){
int c;
cout<<prime(c);
return 0;
}
Brace problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 int prime(int d)
{
    int e=0;

    do
    {

        for(int i=2;i<d;i++)
        {

            if (d%i==0){e=e;}
            else{e+=1;}
            d+=1;
            cout<<e<<endl;

        }
        while(e!=20);    /* while can't be here */
        return e;
    }                    //*while should go here

}                // added here a missing closing brace
int main(){
int c;
cout<<prime(c);
return 0;
}

So, code becomes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int prime(int d)
{
    int e=0;

    do
    {

        for(int i=2;i<d;i++)
        {

            if (d%i==0){e=e;}
            else{e+=1;}
            d+=1;
            cout<<e<<endl;

        }
    }while(e!=20); 
    return e;
}
int main(){
int c;
cout<<prime(c);
return 0;
}
Last edited on
Thanks!!!
Topic archived. No new replies allowed.