+ 2
Code coach (Gotham City)
Please guys what is wrong with my code? #include <iostream> using namespace std; int main() { int x=10; if(x<5){ cout <<"I got this!"; } if(x>=5&&x>=10){ cout <<"Help me Batman"; } else{ cout <<"Good Luck out there"; } return 0; }
3 ответов
+ 2
I think you mistyped >= instead of <= in the second condition when checking 'x' against ten.
Also, the entire if-statement should be an if - if else - else - statement, otherwise two clauses will be executed instead of one, because the first if currently is independant from the second.
Furthermore, 'x' should be taken as input, not initialized to ten from the start.
You should also check if all the output phrases are correct according to the exercise description.
0
It works now bro, thanks
0
My code
#include <iostream>
using namespace std;
int main() {
int b;
cin>>b;
if (b<5){
cout << "I got this!";
}
if (b>5 && b==10){
cout << "Help me Batman";
}
if (b>10){
cout << "Good Luck out there!";
}
if (b==5){
cout << "Help me Batman";
}
return 0;
}