Hi
I am new to programming.
this code's are written in 'C' .
please let me know what's wrong in it
Thanks
error on Line #31
\4-16v1.c|31|error: syntax error before '{' token|
Hi
I am new to programming.
this code's are written in 'C' .
please let me know what's wrong in it
Thanks
error on Line #31
\4-16v1.c|31|error: syntax error before '{' token|
1 hard to read code in the txt file, try posting it on the post with the code button....
2 your code, IF you even wrote it, is a complete mess!
3 the error on 31 is the least of your probs with this code
Here's what I see in Notepad, after a bit of editing:
Code:#include<stdio.h> #include<conio.h> void display(int z); void display2(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); /* your main function should call the other functions, but they should not be included inside main(), so: */ display(z); display2(z); printf("Press enter to continue, when ready\n"); getchar(); return 0; } //end of main 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 display2(int z) //make it display2. You can't have two functions with the same name and parameters { 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 }
Last edited by Adak; 01-08-2013 at 12:47 AM.
here is the errors i get from your code adak...
(18): error #2048: Undeclared identifier 'z'.
(10): warning #2115: Local 'x' is initialized but never used.
(27): error #2156: Unrecognized declaration.
(28): error #2048: Undeclared identifier 'a'.
(28): error #2048: Undeclared identifier 'b'.
(28): error #2048: Undeclared identifier 'c'.
(28): error #2048: Undeclared identifier 'd'.
(28): error #2069: Initializer must be constant.
(29): warning #2099: Missing type specifier; assuming 'int'.
(29): error #2001: Syntax error: expected ')' but found 'string constant'.
(29): error #2120: Redeclaration of 'printf', previously declared at C:\Program Files\PellesC\Include\stdio.h(159); expected 'int __cdecl function(const char * restrict, ...)' but found 'int __cdecl function()'.
(29): error #2001: Syntax error: expected ';' but found ')'.
(30): warning #2099: Missing type specifier; assuming 'int'.
(31): error #2156: Unrecognized declaration.
(58): error #2168: Operands of '==' have incompatible types 'int *' and 'int'.
(58): warning #2243: Check precedence for operator '&'; use parentheses to clarify.
(82): error #2168: Operands of '==' have incompatible types 'int *' and 'int'.
(82): warning #2243: Check precedence for operator '&'; use parentheses to clarify.
(83): error #2001: Syntax error: expected ';' but found 'printf'.
I just moved the other functions outside main() and gave one of them a different name to differentiate it from the other one. Didn't mean to imply it was OK.
I had to leave.
Here's an error free version, but it can't deliver good results.
Code:#include<stdio.h> #include<conio.h> void display(int x[16],int a,int b,int c,int d); void display2(int x[16],int a,int b,int c,int d,int z); int main(void) { int a,b,c,d,z=0; 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); /* your main function should call the other functions, but they should not be included inside main(), so: */ display(x,a,b,c,d); display2(x,a,b,c,d,z); printf("Press enter to continue, when ready\n"); getchar(); return 0; } //end of main void display(int x[16],int a,int b,int c,int d) { int index = a*8 + b*4 + c*2 + d; printf("%d, %d, %d, %d is %d %%", a, b, c, d, x[index]); getchar(); } //make it display2. You can't have two functions with the same name and parameters void display2(int x[16],int a,int b,int c,int d,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 if(a==1 && b==1 && c==1 && d==1) printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[15]);//1111=15 }