+ 1
This code said compilation error. What's wrong with it?
#include <iostream> using namespace std; int main() { int div=2; int num; bool switch=true cout<<"Please enter a number:"<<endl; cin>>num>>endl; do{ if(num%div>0){ div++; } else{ switch=false; } }while(div<num&&num%div>0) if(switch=true){ cout<<num<<"is a prime number."; } else{ cout<<num<<"is not a prime number."; } return 0; }
4 Respostas
+ 6
Missing semicolons... compilation error is not a guarentee of something being wrong. I get them all the time and run once more to get my errors or working output.
+ 5
Your if at the end will always be true as you are missing the second =.
+ 3
You can not cin into endl.
ie cin>>num>>endl;
is invalid.
+ 2
John Wells Thanks!!