here my code find out my mistake plzzz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

here my code find out my mistake plzzz

#include <iostream> using namespace std; int main() { int num; cout<<"what is 9+1 ? "<<endl; cin>>num; if(num==10){ cout<<"corrrect answer"<<endl; } ( num!=10);{ cout<<"incorrect answer"<<endl; } return 0; } //when i type 10 compiler is giving me both cout so find out my mistake plzzz //corrrect answer //incorrect answer

9th Sep 2017, 6:42 PM
cяεαтιvε мαsтεяs
cяεαтιvε мαsтεяs - avatar
5 Answers
+ 4
that is because you did ( num!=10); which is not an if statement so both gets executed. change it to if (num != 10)
9th Sep 2017, 6:45 PM
Jordan Chapman
Jordan Chapman - avatar
+ 3
instead of (num!=10) just place "else" in there. everything is about "if else" statement. read about then and this will be clear for you
9th Sep 2017, 6:44 PM
Paul
+ 3
#include <iostream> using namespace std; int main() { int num; cout<<"what is 9+1 ? "<<endl; cin>>num; if(num==10){ cout<<"corrrect answer"<<endl; } else{ cout<<"incorrect answer"<<endl; } return 0; }
9th Sep 2017, 6:44 PM
Paul
+ 1
Correct code #include <iostream> using namespace std; int main() { int num; cout<<"what is 9+1 ? "<<endl; cin>>num; if(num==10){ cout<<"corrrect answer"<<endl; }else{ cout<<"incorrect answer"<<endl; } return 0; }
9th Sep 2017, 6:44 PM
Alexandru Burcă
Alexandru Burcă - avatar
0
thanks for help its worked ☺☺😊😀
9th Sep 2017, 7:13 PM
cяεαтιvε мαsтεяs
cяεαтιvε мαsтεяs - avatar