+ 1
Can someone tell me what's wrong with this? It says something about the switch == false isn't right, but I can't see anything.
#include <iostream> using namespace std; int main(){ int div=2; int num; bool sw = true; cout<<"Please enter a number:"<<endl; cin>>num; while(div<num&&num%div>0){ if(num%div>0){ div++; } else{ switch == false; } } if(sw==true){ cout<<num<<" is a prime number."; } else{ cout<<num<<" is not a prime number."; } return 0; }
3 Réponses
+ 3
Don't you think that the if statement inside the while is redundant and prevents the else part from getting evaluated? Or maybe you should remove the second condition of the while? How do you fix that Thomas Wald ?
while ( (div < num) && (num % div > 0) ) {
if(num % div > 0) {
div++;
}
else {
sw = false;
}
}
+ 1
switch is a statement + its not defined ass a bool i think you meant to put sw (since you already defined it above )
0
try sw= false, as that's the name of your boolean and the assignment operator is "=" not "=="