This code said compilation error. What's wrong with it? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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; }

24th Jul 2018, 9:37 PM
Thomas Wald
Thomas Wald - avatar
4 Antworten
+ 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.
24th Jul 2018, 9:53 PM
John Wells
John Wells - avatar
+ 5
Your if at the end will always be true as you are missing the second =.
24th Jul 2018, 9:54 PM
John Wells
John Wells - avatar
+ 3
You can not cin into endl. ie cin>>num>>endl; is invalid.
25th Jul 2018, 8:59 AM
Jared Bird
Jared Bird - avatar
+ 2
John Wells Thanks!!
25th Jul 2018, 4:12 AM
Thomas Wald
Thomas Wald - avatar