0
Could someone please tell me all the errors with this code? I couldn't really understand what they were.
#include <iostream> using namespace std; int main(){ int div=2; int num; bool switch==true; cout<<"Please enter a number:"<<endl; cin>>num; 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; }
2 Respuestas
+ 2
I only saw three errors:
- you are using '==' to assign a variable, it should be '='.
- switch is a reserved word, so you can not use it as the name of a variable.
- missing a ';' after this expression: while (div<num&&num%div>0)
#include <iostream>
using namespace std;
int main(){
int div=2;
int num;
bool sw = true;
cout<<"Please enter a number:"<<endl;
cin>>num;
do
{
if(num%div>0)
{
div++;
}
else
{
sw = false;
}
} while (div<num&&num%div>0);
if(sw == true)
{
cout<<num<<" is a prime number.";
}
else
{
cout<<num<<" is not a prime number.";
}
return 0;
}
+ 1
Mickel thank you!