Go Down

Topic: help for the program for water tank (Read 4 times) previous topic - next topic

mkbutan

thanks for giving me the kick start idea
but i am getting this error in Line #13 and #22
( I am using Code::Blocks 10.05 )

\4-16v1.c||In function `main':|
\4-16v1.c|13|error: syntax error before "void"|
\4-16v1.c|22|error: syntax error before '{' token|
    ||=== Build finished: 2 errors, 0 warnings ===|


the code's are as
I know its still wrong but please help
thanks
Code: [Select]

#include<stdio.h>
#include<conio.h>
void display(int z);
int main(void)
{
     int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100}

     //printf("Enter the Val of A,B,C,D\n");
     //scanf("%d,%d,%d,%d",&a,&b,&c,&d);
     //printf("Val of a,b,c,d,%d,%d,%d,%d",a,b,c,d);

void display(int z);
{
  int index = a*8 + b*4 + c*2 + d;
   printf("%d, %d, %d, %d is %d %%", a, b, c, d, x[index]);
}
     getch();
     }


{

    void display(int z)

{
    if(a==0 && b==0 && c==0 && d==0)
    printf("%d,%d,%d,%d is %d%% EMPTY",a,b,c,d,x[0]);//0000=00
    }
{
    if(a==0&&b==0&&c==0&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[1]);//0001=01
    }
{
    if(a==0&&b==0&&c==1&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[2]);//0010=02
    }
{
    if(a==0&&b==0&&c==1&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[3]);//0011=03
    }
{
    if(a==0&&b==1&&c==0&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[4]);//0100=04
    }
{
    if(a==0&&b==1&&c==0&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[5]);//0101=05
    }
{
    if(a==0&&b==1&&c==1&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[6]);//0110=06
    }
{
    if(a==0&&b==1&&c==1&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[7]);//0111=07
    }
{
    if(a==1&&b==0&&c==0&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[8]);//1000=08
    }
{
    if(a==1&&b==0&&c==0&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[9]);//1001=09
    }
{
    if(a==1&&b==0&&c==1&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1010=10
    }
{
    if(a==1&&b==0&&c==1&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1011=11
    }
{
    if(a==1&&b==1&&c==0&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[12]);//1100=12
    }
{
    if(a==1&&b==1&&c==0&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[13]);//1101=13
    }
{
    if(a==1&&b==1&&c==1&&d==0)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[14]);//1110=14
    }
{
    else(a==1&&b==1&&c==1&&d==1)
    printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[15]);//1111=15
    }

}

"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ??????°?i??
                           AND
                           yes
                           PROGRAMMING

AWOL

#36
Jan 07, 2013, 09:20 pm Last Edit: Jan 07, 2013, 09:25 pm by AWOL Reason: 1
Can you see a closing brace in main?
I can't
(The error message line numbers are dead accurate)

Then there's the confused scope rules
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

mkbutan


Can you see a closing brace in main?
I can't
(The error message line numbers are dead accurate)

Then there's the confused scope rules


Line #5 {

Line#19 }
do you mean anything else
pl explain
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS"
                           ??????°?i??
                           AND
                           yes
                           PROGRAMMING

AWOL

Most C implementations don't permit nested functions (personally, I think they're quite a good idea), so your braces are misplaced, hence the error messages.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

PaulS

It looks to me like you are just splattering code around without a clue as to what you are doing.

main does not terminate correctly.
display has a body, even though it is NOT a function declaration.
getch() returns a value that you discard. It won't work on an Arduino, anyway, since the Arduino doesn't have a keyboard.
printf() won't work, because the Arduino doesn't have a console.

You have no clue when to use { and }, and when not to.

Go Up