0
Int a; for(a=2; a<=50;a+=2) {If( a != 10 and a != 20) cout<<a;} why the program still output value 10 and 20 in looping?
I confused process looping ?
3 Réponses
+ 1
Are you using c++? If you are then your code is wrong. In c++, there is no "and" operator. Hence in an if statement, if you want more than one condition, then you have to use the && operator instead of the word "and".
So the code looks like this in c++
#include <iostream>
using namespace std;
int main(){
int a;
for(a=2;a<=50;a+=2){
if((a! != 10 && a != 20){
cout << a << endl;
}
}
return 0;
}
0
Thanks Eddy for your answer, but my trouble not in that code c++ but in the output of program.
Because while i simulate the code in manual, values 10 and 20 it must still write in output. because if a = 10, it will be false for a != 10 and will be true for a != 20. So, the output is false, because false and true = false.
0
But, if i compile the code in compiler the values 10 and 20 is not write in output