Answer the question
In order to leave comments, you need to log in
How to correctly write condition fulfillment at certain iterations of a loop in C++?
Hello!
Please tell me how to write the following condition:
int main(){
bool D=false;
for (int i=1; i<10; i++)
{
for (int j=1; j<10; j++)
{
for (int k=1; k<10; k++)
{
if ( i==3 && j==2 && j==3 && j==4 && k==4 ){
D=true;
cout << D << endl;
}
}
}
}
return 0;
}
int main(){
bool D=false;
for (int i=1; i<10; i++)
{
for (int j=1; j<10; j++)
{
for (int k=1; k<10; k++)
{
if ( i==3 && j==2 && j==3 && j==4 && k==4 ){
D=true;
cout << D << endl;
}
}
}
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
Perhaps you meant
if ( i==3 && (j==2 || j==3 || j==4) && k==4 ) {
// ...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question