+ 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
5 Respostas
+ 4
that is because you did
( num!=10);
which is not an if statement so both gets executed. change it to
if (num != 10)
+ 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
+ 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;
}
+ 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;
}
0
thanks for help its worked ☺☺😊😀