0

I just wrote this and i cant find problem. I work with codeblocks and it writing this problem

error: expected 'while' before '{' token
=== Build finished: 1 errors, 1 warnings)

But I cant wrote while there , because its not correct. Can someone help me please? Sorry for my eng.

printf("Put numbers for some reason\n");

int cislo;
int s0,s1,s2,s3,s4,s5,s6,s7,s8,s9;

while(scanf("%d",&cislo)==1){
   if (cislo<0)
      printf ("Cislo %d, je zaporne, takove neberu", cislo);
}

s0=s1=s2=s3=s4=s5=s6=s7=s8=s9=0;


do (cislo/10);
    {
    switch (cislo%10);

    case 0; ++s0;  break;
    case 1; ++s1;  break;
    case 2; ++s2;  break;
    case 3; ++s3;  break;
    case 4; ++s4;  break;
    case 5; ++s5;  break;
    case 6; ++s6;  break;
    case 7; ++s7;  break;
    case 8; ++s8;  break;
    case 9; ++s9;  break;
    }

 while (cislo>0);

 printf("0  %d x \n 1  %d x \n 2  %d x \n 3  %d x \n 4  %d x \n 5  %d x \n 6  %d x \n 7  %d x \n 8  %d x \n 9  %d x \n",s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);

 return 0;
}

In the final it must print something like this:

100
Number: 100 include this numbers :
0 ...  2x
1 ...  1x
2 ...  0x
3 ...  0x
4 ...  0x
5 ...  0x
6 ...  0x
7 ...  0x
8 ...  0x
9 ...  0x
1
  • You have an extra ; on the line that starts with do and it should actually be while, not do. You are missing braces in the switch statement and have an extra ;. Commented Oct 19, 2012 at 18:33

4 Answers 4

1
do 
{
cislo /= 10;
switch (cislo%10);

case 0; ++s0;  break;
case 1; ++s1;  break;
case 2; ++s2;  break;
case 3; ++s3;  break;
case 4; ++s4;  break;
case 5; ++s5;  break;
case 6; ++s6;  break;
case 7; ++s7;  break;
case 8; ++s8;  break;
case 9; ++s9;  break;
}

while (cislo>0);

Try this?

Sign up to request clarification or add additional context in comments.

2 Comments

Ok guys, thank you very much for your answers! Now it works, not corectly for 100% but it works.
@user1760185 selecting an answer is Stack Overflow's method of saying "thank you" :-)
1

A do .. while statement has this form:

do statement while (expression)

In your example you have two statements:

(cislo/10);

and another compound statement { ... }. This does not make any sense.

6 Comments

That's a semi-colon, not a comma :)
since when is do(statement){ }while() correct? It was do{ }while() IIRC?
@PrototypeStark (cislo/10); is actually a valid statement. It is called an expression statement:
@ouah I haven't ever seen anyone use it like that before. Is it in c99 or something? I have always seen do { statements } while(cond);
do statement while (expression) is right. { ... } is a statement also.
|
1

do (cislo/10); should be

do 
{ 
  /* your code */ 
} while (cislo/10);

Each case X; should be case X:.

As pointed by hexist, a switch is written like this:

switch (condition) {
  case X:
    /*something*/
    break;
}

1 Comment

And there needs to be a brace enclosing the case statements .. ie switch (..) { and then the closing } at the end
0

Remove ";" after do() .

do (cislo/10)
{
switch (cislo%10);

2 Comments

but keep it after switch (cislo%10);?
No, switch should be like switch(){case:...} . I feel it is better to read some C language book...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.