I having trouble to figure || operator work but when I expected it to print 0 but it print 2. I thought I tell it to "if name is 0 and B is 1 it should not print or name is 0 and b = 5 it should not print" can anyone tell me where I go wrong?
<cstdio> //stdio.h is a C header and it works but is not ideal to use in c++
'B' is not 1.
'B' - 'A' is 1 in ascii.
B is 1 it should not print or name is 0 and b = 5 makes no sense to me.
are you confusing 5 and S visually? Also case matters, b and B are different whether in text data or variable names (unclear).
char name[15] can be said as
char name[] = "whatever"
you don't need to specify the length when you initialize it this way.
Based on @jonnin's comment it seems the original post was edited, as I see nothing that would evaluate B as 1 or lower case 'b' being involved, or the number 5 relating to 'S'.
To that end, I see this question
but when I expected it to print 0 but it print 2
With a general inquiry as the meaning or purpose of the "||" operator, as in this code as posted at this time
2.the reason I say about B =1 is because the position about "Budi" is first and it also apply with S after it finish counting Budi(not include space) and add up with S it will be 5.
But now I understand where I go wrong now because the char[15] is like factorial now it make sense to me why it will be print both of the B and S
Your code isn't counting by position, per se (it's counting the occurrences of B's and S's)...it's sequencing through the positions in the array, in which the space is considered at position 4.