Program for the Wire less Water Level Indicator

Hi
I am new to programming
this code's are written in 'C' (sorry i found C++ forum for this)
please let me know whats wrong in it

error on Line #31
\4-16v1.c|31|error: syntax error before '{' token|

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#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)
    {
        int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};

    }

    {


{
    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
    }

}
Line 13: This is a function prototype, not a declaration that matches with the following block on lines 14-18. Even if it were, it's illegal to define a function inside another function (in this case, inside of main()).

Lines 31 on: Why is there random code outside of any function body? What is it supposed to do there?
hi
Thanks for the reply
can you please explain me in detail what is wrong should I //Comment #13
#13 //void display(int z);



Why is there random code outside of any function body? What is it supposed to do there?


and which random no you are talking about
help me please
closed account (18hRX9L8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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 Values of A,B,C,D (EX: 1,0,1,1 (Only 1s and 0s)).\n");
     scanf("%d,%d,%d,%d",&a,&b,&c,&d);
     printf("\nYou entered: \"%d,%d,%d,%d\"\n",a,b,c,d);


void display(int z);
{
	int index = a*8 + b*4 + c*2 + d;
    printf("The probability of your pattern is %d%%",x[index]);
    getch();
}
}
Last edited on
do you mean to say like that

but there are still errors on Line #25; #26; #85

\4-16v1.c||In function `display':|
\4-16v1.c|25|error: `a' undeclared (first use in this function)|
\4-16v1.c|25|error: (Each undeclared identifier is reported only once|
\4-16v1.c|25|error: for each function it appears in.)|
\4-16v1.c|25|error: `b' undeclared (first use in this function)|
\4-16v1.c|25|error: `c' undeclared (first use in this function)|
\4-16v1.c|25|error: `d' undeclared (first use in this function)|
\4-16v1.c|26|error: `x' undeclared (first use in this function)|
\4-16v1.c|85|error: syntax error before "else"|
||=== Build finished: 8 errors, 0 warnings ===|

Please HELP

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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, is :-%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)
    {
    {
        int a,b,c,d;
     int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};
    }
{
    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
    }
}
above code having lot of errors use below code

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
void display(int z)
    {
		
			int a,b,c,d;
			int x[16] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};
		
		
			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
		
		
			else if(a==0 && b==0 && c==0 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[1]);//0001=01
		
		
			else if(a==0 && b==0 && c==1 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[2]);//0010=02
		
		
			else if(a==0 && b==0 && c==1 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[3]);//0011=03
		
		
			else if(a==0 && b==1 && c==0 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[4]);//0100=04
		
		
			else if(a==0 && b==1 && c==0 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[5]);//0101=05
		
		
			else if(a==0 && b==1 && c==1 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[6]);//0110=06
		
		
			else if(a==0 && b==1 && c==1 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[7]);//0111=07
		
		
			else if(a==1 && b==0 && c==0 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[8]);//1000=08
		
		
			else if(a==1 && b==0 && c==0 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[9]);//1001=09
		
		
			else if(a==1 && b==0 && c==1 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1010=10
		
		
			else if(a==1 && b==0 && c==1 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[10]);//1011=11
		
		
			else if(a==1 && b==1 && c==0 && d==0)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[12]);//1100=12
		
		
			else if(a==1 && b==1 && c==0 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[13]);//1101=13
		
		
			else 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 if(a==1 && b==1 && c==1 && d==1)
				printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[15]);//1111=15
	}
dear thanks
for the first time there is no ERROOOOOOOOOR

but the output is not proper it gives some random number's

Input was 1100 it should be x[12] =90


 Enter the Val of A,B,C,D
1100
Val of a,b,c,d, is :-1100,43,6039568,172
--------------------------------
Process exited with return value 3221225477
Press any key to continue . . .


Input was 1010 it should be x[10] =75


Enter the Val of A,B,C,D
1010
Val of a,b,c,d, is :-1010,43,5122064,172
--------------------------------
Process exited with return value 3221225477
Press any key to continue . . .



what are these numbers???
is my Compiler Dev-C++ ; code::blocks not working properly
I have upgraded it to the latest version
Dev-C++-Ver 5.3.0.3 and code::blocks to 12.11
Last edited on
How are you entering numbers? I don't think you can just enter 1100 to make a equal to 1, b equal to 1, etc... That would make your variables b, c, and d spit out random numbers. When you declare a variable, your program grabs a free chunk of memory big enough to hold that type... Regardless what that memory currently holds! So you can never assume that your variable is equal to anything unless you set it. Also, your if/else chain doesn't catch odd input. Try adding this to the end:

else printf("Something wierd happened");

And your array has the potential to do funny stuff. Try clearing the brackets to allow your compiler to set the number of elements needed.

int x[] = {0,10,20,25,30,40,50,60,70,75,80,90,100,100,100,100};
Try entering 1 ENTER, 1 ENTER, 0 ENTER, 0 ENTER. Or maybe "1 1 0 0ENTER". I don't know the finer points of C style I/O.
Last edited on
closed account (18hRX9L8)
scanf("%d,%d,%d,%d",&a,&b,&c,&d);

You need to enter like this example: 1,0,1,1. You HAVE to.
Please use my code which I put a couple of posts up, it compiles with no errors and runs FINE.
Last edited on
Don't use ',' in scanf use following code.

scanf("%d%d%d%d",&a,&b,&c,&d);

If you use ',' in scanf you should give input in that format like 1,0,1,1.
If you don't use ',' you can enter values in any way but one space is must to indicate next number. Ex 1 0 1 1 ENTER OR 1 ENTER 0 ENTER 1 ENTER 1 ENTER

One more important thing is you should pass this a,b,c,d values to display function if you want to access that values in that function.
Last edited on
Thanks Mr. usandfriends
your code's are working very fine with all the 16 types of input
with 1,0,1,1 type of entering ','
thanks once again
Topic archived. No new replies allowed.