What's wrong? C++ | Gotham City Challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

18th Feb 2020, 6:43 AM
Dolev
Dolev - avatar
40 Answers
+ 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
18th Feb 2020, 6:57 AM
Taste
Taste - avatar
+ 4
the output is case sensitive, look at the question again and see the correct output https://www.sololearn.com/coach/41?ref=app
18th Feb 2020, 7:31 AM
Taste
Taste - avatar
+ 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; }
19th Feb 2020, 10:04 AM
Denis Evstigneev
+ 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
20th Feb 2020, 4:29 AM
Tanmay Gupta
Tanmay Gupta - avatar
+ 3
عبدالرحمن المطيري please don't spam here
20th Feb 2020, 4:28 AM
Tanmay Gupta
Tanmay Gupta - avatar
+ 3
The program works, but first you must give an initial value of x
4th Apr 2020, 8:11 PM
Qutaba Qais Mahmood
Qutaba Qais  Mahmood - avatar
+ 2
i just tried it with exact same code. it passed with no problem. ~ swim ~ what do you think ?
18th Feb 2020, 7:55 AM
Taste
Taste - avatar
+ 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
19th Feb 2020, 11:27 AM
Harsh Deep Singh
Harsh Deep Singh - avatar
+ 2
The program can run when you give a value to x
19th Feb 2020, 9:10 PM
Qutaba Qais Mahmood
Qutaba Qais  Mahmood - avatar
+ 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
18th Feb 2020, 6:50 AM
Taste
Taste - avatar
+ 1
nope its correct, 5 is "help me" 10 is the problem. i updated the code from before you can test it again
18th Feb 2020, 7:08 AM
Taste
Taste - avatar
+ 1
i'm sure its not bugged take ~ swim ~'s suggestion and try to fix it
18th Feb 2020, 7:24 AM
Taste
Taste - avatar
+ 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.
18th Feb 2020, 8:08 AM
Dolev
Dolev - avatar
+ 1
~ swim ~ Aa.. It's okey. Might happens to everyone :)
18th Feb 2020, 8:25 AM
Dolev
Dolev - avatar
+ 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; }
19th Feb 2020, 12:08 PM
MOHD AYAZ ALAM
MOHD AYAZ ALAM - avatar
+ 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"; }
19th Feb 2020, 8:52 PM
Abhishek Singh
Abhishek Singh - avatar
+ 1
there is variable “x” without value and programm can’t do “if else stairs”
19th Feb 2020, 10:19 PM
Малолетний Дотер
Малолетний Дотер - avatar
+ 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; }
25th Feb 2020, 4:56 AM
Harshit
Harshit - avatar
0
missing else probably ?
18th Feb 2020, 6:47 AM
Taste
Taste - avatar
0
Taste but I added 'else' in the end of the code. Is it incorrect?
18th Feb 2020, 6:49 AM
Dolev
Dolev - avatar