+ 1
What's wrong? C++ | Gotham City Challenge
I don't understand what's wrong here. Can you please help me? @@@@@@@@ #include <iostream> using namespace std; int main() { int x; if(x<5) { cout<< "I got this!"; } if(x<10) { cout<< "Help me Batman"; } else{ cout<< "Good luck out there!"; } return 0; }
40 Respuestas
+ 5
you can use <= instead of < for that matter
look at this test. are you sure 3 have right output ?
https://code.sololearn.com/cMw0MYj8KwDL/?ref=app
+ 4
the output is case sensitive, look at the question again and see the correct output
https://www.sololearn.com/coach/41?ref=app
+ 4
It works
Probably...... DD
#include <iostream>
using namespace std;
string b="I got this!", c="Help me Batman", d="Good Luck out there!";
int a;
string Batman(int a){
if (a<5) return b;
else if ((a>=5)&&(a<=10)) return c;
else return d;
}
int main(){
cin>>a;
cout<<Batman(a);
return 0;
}
+ 4
TRY THIS:
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
if (n<=4)
cout<<"I got this!";
else if (n>4 && n<11)
cout<<"Help me Batman";
else
cout<<"Good Luck out there!";
return 0;
}
it returned all the 5 test cases correct and solved
+ 3
عبدالرحمن المطيري please don't spam here
+ 3
The program works, but first you must give an initial value of x
+ 2
i just tried it with exact same code.
it passed with no problem.
~ swim ~ what do you think ?
+ 2
Here your result is
I got this!
Help me batman
Because int x holds a garbage value and condition 1 is true and also condition 2 is true.
If u want to execute only one comdition then u will use else if
+ 2
The program can run when you give a value to x
+ 1
no. its corect,
lets say the input is 3. now follow the flow of your program, you'll see what i meant by missing else
+ 1
nope its correct, 5 is "help me"
10 is the problem. i updated the code from before you can test it again
+ 1
i'm sure its not bugged
take ~ swim ~'s suggestion and try to fix it
+ 1
Taste ~ swim ~ I send before the full code, but: OHHHHHHH
I thought the system itself generate random inputs so I didn't add 'cin'.
Now I did that and I completed this challenge ;) LOL I was trying to figure out what's wrong like 1 hour.
*THANKS A LOT* for you help and your patience, you helped me so much.
+ 1
~ swim ~ Aa.. It's okey. Might happens to everyone :)
+ 1
#include <iostream>
using namespace std;
int main() {
int a;
cin>>a;
if(a<5){
cout<<"I got this!";}
else if (a<=10){
cout<<"Help me Batman";
}else{
cout<<"Good Luck out there!";
}
return 0;
}
+ 1
Use this if logic instead of yours.
If (x >5 & & x<10)
{ cout<<"help me batman" ;
}
else if ( x <5)
{
Cout" i got this";
}
+ 1
there is variable “x” without value and programm can’t do “if else stairs”
+ 1
#include <iostream>
using namespace std;
int main() {
int criminal_case;
cin>>criminal_case;
if(criminal_case>=0){
if(criminal_case>=0 && criminal_case<5){
cout<<"I got this!";
}
else if(criminal_case>=5 && criminal_case<=10){
cout<<"Help me Batman";
}
else{
cout<<"Good Luck out there!";
}
}
else {
cout<< "only positive number enter";
}
return 0;
}
0
missing else probably ?
0
Taste but I added 'else' in the end of the code. Is it incorrect?