Karina Sakurai
Karina Sakurai

Reputation: 31

Expected identification or '(' before return 0?

I am trying to compile this on C, but I can't see where is wrong.

#include <stdio.h>

int verifica_quatro (int N, int M)
{   

    if  (M==N) 
        return 1;

    else 
        return -1;

}

int verifica_tres (int N, int M)
{

    if  (M==N) 
        return 1;

    else 
        return -1;

}

int verifica_dois (int N, int M)
{

    if  (M==N) 

        return 1;

    else 
        return -1;

}

int verifica_grupo (int N, int M)
{

    if (M == 0)
        M= 100;

    if (N == 0)
        N= 100;

    N= (N-1)/4;
    M= (M-1)/4;

    if (N == M)
        return 1;
    else
        return -1;

}

int main(void)
{
    int V, N, M, r;

    int valor = -1;

    int cont = 4;

    scanf("%d %d %d", &V, &N, &M);

    while !(M==0 && N==0 && V==0) {

        while (M>=10000) {
            M= M/10;
        }

        while (N>=10000) {
            N= N/10;
        }

    while (cont>0 && valor<0){

    if (cont == 4){
        r = verifica_quatro(N,M);
        valor = V*2500*r;

    }else if(cont == 3){
        N = N/10;
        M = M/10;
        r = verifica_tres(N,M);
        valor = V*510*r;
    }else if(cont == 2){
        N = N/100;
        M = M/100;
        r = verifica_dois(N,M);
        valor = V*77*r;
    }else if(cont == 1){
        N = N/100;
        M = M/100;
        r = verifica_grupo(N,M);
        valor = V*34*r;
    }

    cont--;

    }


      }

    if (valor<0)
        valor = 0;

    printf ("%d\n", valor);
      printf ("Digite M, N e V");
      scanf ("%d %d %d", &M, &N, &V);


    }

    return 0;
}

Upvotes: 1

Views: 70

Answers (3)

ashiquzzaman33
ashiquzzaman33

Reputation: 5741

Here is your code that compile successfully.

#include <stdio.h>
int verifica_quatro (int N, int M)
{

    if  (M==N)
        return 1;

    else
        return -1;

}

int verifica_tres (int N, int M)
{

    if  (M==N)
        return 1;

    else
        return -1;

}

int verifica_dois (int N, int M)
{

    if  (M==N)

        return 1;

    else
        return -1;

}

int verifica_grupo (int N, int M)
{

    if (M == 0)
        M= 100;

    if (N == 0)
        N= 100;

    N= (N-1)/4;
    M= (M-1)/4;

    if (N == M)
        return 1;
    else
        return -1;

}

int main(void)
{
    int V, N, M, r;

    int valor = -1;

    int cont = 4;

    scanf("%d %d %d", &V, &N, &M);

    while (!(M==0 && N==0 && V==0))     //Here a problem with ()
    {

        while (M>=10000)
        {
            M= M/10;
        }

        while (N>=10000)
        {
            N= N/10;
        }

        while (cont>0 && valor<0)
        {

            if (cont == 4)
            {
                r = verifica_quatro(N,M);
                valor = V*2500*r;

            }
            else if(cont == 3)
            {
                N = N/10;
                M = M/10;
                r = verifica_tres(N,M);
                valor = V*510*r;
            }
            else if(cont == 2)
            {
                N = N/100;
                M = M/100;
                r = verifica_dois(N,M);
                valor = V*77*r;
            }
            else if(cont == 1)
            {
                N = N/100;
                M = M/100;
                r = verifica_grupo(N,M);
                valor = V*34*r;
            }

            cont--;

        }


    }

    if (valor<0)
        valor = 0;

    printf ("%d\n", valor);
    printf ("Digite M, N e V");
    scanf ("%d %d %d", &M, &N, &V);


//}  This should be deleted

    return 0;
}

In your outer while loop you write

while !(M==0 && N==0 && V==0)

Which is syntax error it should be

while (!(M==0 && N==0 && V==0))

And braces before return 0 is extra, it should be removed.

Upvotes: 1

Kickaha
Kickaha

Reputation: 3857

These two lines at the end are not in any function. Plus what chqrlie said..

return 0;
}

Upvotes: 0

chqrlie
chqrlie

Reputation: 144969

You have a missing set of parentheses in

while !(M==0 && N==0 && V==0)

fix it this way:

while (!(M==0 && N==0 && V==0))

Or more confusingly:

while (M|N|V)

Also: indent your code with four spaces per level and NO TABS!

Upvotes: 0

Related Questions