skywaker
asked on
c++ nested if
Hi , i am trying to create a nested if in c++ , i can't get the logic right ,code here
if (position_six_A !='15')
{
position_six = position_six+1;
}
else if (position_six_A = '15')
{
position_six=0;
}
else if (position_five_A !='J')
{
position_five = position_five - 1;
position_six = position_six + 1;
}
else if (position_five_A ='J')
{
position_five=32;
}
else if (position_four_A !='15')
{
position_four = position_four + 1;
position_five = position_five - 1;
position_six = position_six + 1;
}
else if (position_four_A ='15')
{
position_four = 0;
}
else if (position_three_A != 'J')
{
position_three = position_three - 1;
position_four = position_four + 1;
position_five = position_five - 1;
position_six = position_six + 1;
}
else if (position_three_A ='J')
{
position_three=32;
}
ASKER
hi , sorry , it is not a loop but a nested if
ASKER
hi the 15 should be 5
>> hi , sorry , it is not a loop but a nested if
Yes, I see you edited the question ;)
The same tutorial I posted earlier also explains if statements. I still recommend reading it.
And, I'm still not sure what you're trying to do, or what your question is.
Yes, I see you edited the question ;)
The same tutorial I posted earlier also explains if statements. I still recommend reading it.
And, I'm still not sure what you're trying to do, or what your question is.
ASKER
I am trying to test each of the conditions. Ie: if condition 1 is true it must test the next condition
if position_six_A !='5'
then position_six=position_six+ 1
then it must check
position_five
if position_five_A !="J"
position_five=position_fiv e-1
i want to test each condition.
if position_six_A !='5'
then position_six=position_six+
then it must check
position_five
if position_five_A !="J"
position_five=position_fiv
i want to test each condition.
So, something like this ?
if (condition1) {
if (condition2) {
/* ... */
}
else {
/* ... */
}
}
else {
/* ... */
}
ASKER
hi , does not work below is the vb code of what want t o do
If position_six_A <> "5" Then
position_six = position_six + 1
ElseIf position_six_A = "5" Then
position_six = 0
Else
If position_five_A <> "E" Then
position_five = position_five - 1
position_six = position_six + 1
ElseIf position_five_A = "E" Then
position_five = 32
Else
If position_four_A <> "5" Then
position_four = position_four + 1
position_five = position_five - 1
position_six = position_six + 1
ElseIf position_four_A = "5" Then
position_four = 0
Else
If position_three_A <> "E" Then
position_three = position_three - 1
position_four = position_four + 1
position_five = position_five - 1
position_six = position_six + 1
ElseIf position_three_A = "E" Then
position_three = 32
Else
If position_two_A <> "5" Then
position_two = position_two + 1
position_three = position_three - 1
position_four = position_four + 1
position_five = position_five - 1
position_six = position_six + 1
ElseIf position_two_A = "5" Then
position_two = 0
Else
If position_one <> "5" Then
position_one = position_one + 1
position_two = position_two + 1
position_three = position_three - 1
position_four = position_four + 1
position_five = position_five - 1
position_six = position_six + 1
ElseIf position_one <> "0" Then
position_one = 0
end If
End If
End If
End If
End If
End If
What does not work ?
Unless I am very much mistaken (I could be, I don't know VB), your VB code doesn't contain any nested ifs, it is just a whole bunch of if/else statements one after the other and it's just the way it's formatted that make it look nested. I thinks just the way that it has been formatted that is making it look like they are nested and, therefore, confusing you.
give more detail so that we can understand your problem clearly
the code you post so confused, plz describe via natural language :D
the code you post so confused, plz describe via natural language :D
and the VB code you've post, I thnk it wrong(???)
if you look at your VB logic it fails...
If position_six_A <> "5" Then
position_six = position_six + 1
ElseIf position_six_A = "5" Then.................this is implied if initial if failed
position_six = 0
Else ....... ??????
.... never can get here
Endif
If position_six_A <> "5" Then
position_six = position_six + 1
ElseIf position_six_A = "5" Then.................this is implied if initial if failed
position_six = 0
Else ....... ??????
.... never can get here
Endif
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://cplusplus.com/doc/tutorial/control/
(consider also reading the rest of that tutorial, to get a better understanding of programming in C++)
2) '15' is not a valid character literal, as it contains two characters.
3) = is not the same as ==. The first (=) is the assignment operator, while the second (==) is a comparison operator.
Other than that, I'm not sure what you're trying to do.