Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #30 on: January 07, 2013, 12:35:42 pm » |
if(a=0&&b=0&&c=0&&d=0) I know it is in a comment, and you didn't post it between CODE TAGS, but those are assignments, and will ALWAYS be false. Good luck with "printf" thanks sir but I did not understand what are you trying to say pl explain
|
|
|
|
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #31 on: January 07, 2013, 12:51:47 pm » |
those are assignments ..using "=", not comparisons which would use "=="
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #32 on: January 07, 2013, 02:19:11 pm » |
i have put one FUNCTION (Display) in the code's but still not functional is there any way by which we can convert BCD to DEC code's and can be printed out as output I know its wrong please help me to make it right thanks [ the CODE's is for 'C' not for 'ARDUINO' ] #include<stdio.h> #include<conio.h> void display(int z) // function declared Display(int z) int main(void) { int a,b,c,d; int x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; x0=00; x1=10; x2=20; x3=25; x4=30; x5=40; x6=50; x7=60; x8=70; x9=75; x10=80; x11=90; x12=100; x13=0; x14=0; x15=0; 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 ); display(int z) getch(); }
{
void display(int z) //Function CALLED
{ if(a==0&&b==0&&c==0&&d==0) printf("%a,%b,%c,%d is 00% EMPTY",x0);//0000=00 } { if(a==0&&b==0&&c==0&&d==1) printf("%a,%b,%c,%d is 10%",x1);//0001=01 } { if(a==0&&b==0&&c==1&&d==0) printf("%a,%b,%c,%d is 20%",x2);//0010=02 } { if(a==0&&b==0&&c==1&&d==1) printf("%a,%b,%c,%d is 25%",x3);//0011=03 } { if(a==0&&b==1&&c==0&&d==0) printf("%a,%b,%c,%d is 30%",x4);//0100=04 } { if(a==0&&b==1&&c==0&&d==1) printf("%a,%b,%c,%d is 40%".x5);//0101=05 } { if(a==0&&b==1&&c==1&&d==0) printf("%a,%b,%c,%d is 50%",x6 HALF);//0110=06 } { if(a==0&&b==1&&c==1&&d==1) printf("%a,%b,%c,%d is 60%",x7);//0111=07 } { if(a==1&&b==0&&c==0&&d==0) printf("%a,%b,%c,%d is 70%",x8);//1000=08 } { if(a==1&&b==0&&c==0&&d==1) printf("%a,%b,%c,%d is 75%",x9);//1001=09 } { if(a==1&&b==0&&c==1&&d==0) printf("%a,%b,%c,%d is 80%",x10);//1010=10 } { if(a==1&&b==0&&c==1&&d==1) printf("%a,%b,%c,%d is 90%",x11);//1011=11 } { if(a==1&&b==1&&c==0&&d==0) printf("%a,%b,%c,%d is 100% FULL",x12);//1100=12 } { if(a==1&&b==1&&c==0&&d==1) printf("%a,%b,%c,%d is 100% ALARM",x13);//1101=13 } { if(a==1&&b==1&&c==1&&d==0) printf("%a,%b,%c,%d is xXx",x14 );//1110=14 } { else(a==1&&b==1&&c==1&&d==1) printf("%a,%b,%c,%d is XxX",x15);//1111=15 }
}
|
|
|
|
« Last Edit: January 07, 2013, 02:26:26 pm by mkbutan »
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 88
Posts: 9392
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #33 on: January 07, 2013, 02:34:32 pm » |
int x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15; one day long ago in FORTRAN someone invented the array. In C++ it is written as int x[16] = { 0,10,20,25,30, ....,0,0,0} everywhere where you state x3 you should use x[3] (and that for all values of 3 
The other trick to consider is the else keyword void display(int z) { if (a==0 && b==0 && c==0 && d==0) // spaces are free printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[0]); else if (a==0 && b==0 && c==0 && d==1) printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[1]); else if (a==0 && b==0 && c==1 && d==0) printf("%d, %d, %d, %d is %d %%", a,b,c,d, x[2]); else ... //etc }
As you want to handle all 16 possible combinations of bits you can combine the values a,b,c,d into one integer by using bit math to create an index to the array declared above. 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]); }
please read the tutorial pages about arrays in C for more info.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #34 on: January 07, 2013, 02:46:59 pm » |
void display(int z) // function declared Display(int z That's not a function prototype. This is: void display(int z); // function declared Display(int z
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #35 on: January 07, 2013, 03:15:10 pm » |
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 #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 }
}
|
|
|
|
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #36 on: January 07, 2013, 03:20:48 pm » |
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
|
|
|
|
« Last Edit: January 07, 2013, 03:25:27 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #37 on: January 07, 2013, 03:28:07 pm » |
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
|
|
|
|
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #38 on: January 07, 2013, 03:31:05 pm » |
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.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #39 on: January 07, 2013, 03:31:39 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #40 on: January 07, 2013, 03:40:08 pm » |
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.
sir post #32 and #35 says I am Using 'C' but not ARDUINO My project is for ARDUINO First let me learn to program in 'C' after that I will Program the same in ARDUINO I am new to programming I have just learnt 'C' Programming Language that to from YOU TUBE and from net surfing and Book's
|
|
|
|
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Mumbai -INDIA
Offline
Newbie
Karma: 0
Posts: 30
|
 |
« Reply #41 on: January 07, 2013, 03:48:46 pm » |
\4-16v1.c|13|error: syntax error before "void"| \4-16v1.c|23|error: syntax error before '{' token| error on line #13 and #23 #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 } }
|
|
|
|
« Last Edit: January 07, 2013, 03:52:50 pm by mkbutan »
|
Logged
|
"THE LIFE IS VERY SMALL TO LEARN ELECTRONICS" ε∫εζτ√°ηiζ≈ AND yes PROGRAMMING
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #42 on: January 07, 2013, 03:50:59 pm » |
Does that compile? Does it do what you want? Did you have a question? int a,b,c,d; Local variables are not initialized. These contain whatever junk was in memory. int index = a*8 + b*4 + c*2 + d; Now, what do you suppose index equals?
|
|
|
|
« Last Edit: January 07, 2013, 03:53:22 pm by PaulS »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19015
I don't think you connected the grounds, Dave.
|
 |
« Reply #43 on: January 07, 2013, 04:05:46 pm » |
Line 7 missing semicolon. Can I ask what you're trying to do, and why doesn't it involve an Arduino?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
UK
Offline
Tesla Member
Karma: 89
Posts: 6335
-
|
 |
« Reply #44 on: January 07, 2013, 06:30:16 pm » |
First let me learn to program in 'C' after that I will Program the same in ARDUINO I am new to programming I have just learnt 'C' Programming Language that to from YOU TUBE and from net surfing and Book's
It's perfectly fine to learn C++ on its own if you want. In that case I suggest you start with a C++ development environment available on your operating system, and find a C++ forum and/or tutorials to help you learn. There are plenty of both about. I don't think it's reasonable to expect contributors on the Arduino forum to deal with general C++ issues that are not related to Arduino.
|
|
|
|
|
Logged
|
|
|
|
|
|