+ 5

What is wrong with that code please help me I can't figure out

https://sololearn.com/compiler-playground/cwHaCiEelzQ6/?ref=app

23rd Jul 2025, 11:30 AM
Alban
Alban - avatar
16 ответов
+ 3
don't put return 0; on the beginning. it will cause main() to exit immediately. if conditions are enclosed in parenthesis if (points<20) #include <iostream> using namespace std; int main() { // return 0; ❌ wrong int points; cin>>points; cout << points; if (points<20) { ✅ use ( ) cout << "Tu as rouge."<<endl; } return 0; ✅ put return 0; here }
23rd Jul 2025, 11:45 AM
Bob_Li
Bob_Li - avatar
+ 6
Bhushan kale keep your language clean on Sololearn. Personal attacks are unacceptable and will get your account banned.
23rd Jul 2025, 3:36 PM
Brian
Brian - avatar
+ 4
There are two problems with your code. The `return 0;` statement returns a value from the function(in this case, main()) and stops the function. Also, you need to wrap your conditions inside these brackets– ( ) Here is the fixed, working code ``` #include <iostream> using namespace std; int main() { // remove return 0 from here int points; cin>>points; cout << points; if (points<20) { // wrap your condition in parenthesis cout << "Tu as rouge."<<endl; } return 0; // putting it here ensures all code runs before termination } ``` You might want to use `cout <<points << endl;` for better formatting
23rd Jul 2025, 12:03 PM
Vaibhav
Vaibhav - avatar
+ 3
As the code evolves, errors evolve too. Keep trying! Errors are a constant companion to developing code - even for professional programmers. Though you corrected the above problems, new changes added another. The latest problem is that the less-than-or-equal comparison operator is mistyped. It should be <=, not =<.
23rd Jul 2025, 1:30 PM
Brian
Brian - avatar
+ 3
other than being written the wrong way, (most people would put the >= on the left and the <= on the right of &&), your conditions are mostly inverted. also, else does not accept any condition. #include <iostream> using namespace std; int main() { int points; cin>>points; cout <<points <<" points."; if(points>=0 && points<=19) { cout << "Tu as rouge."<<endl; } else if (points>=20 && points<=39){ cout << "Tu as jaune."<<endl; } else if (points>=40 && points<=59){ cout << "Tu as vert pale."<<endl; } else if (points >=60 && points<=79){ cout << "Tu as vert."<<endl; } else if (points>=80 && points<=99){ cout << "Tu as vert +."<<endl; } else{ cout << "Tu ment on peut pas avoir plus de 100 points."<<endl; } return 0;}
23rd Jul 2025, 3:03 PM
Bob_Li
Bob_Li - avatar
+ 3
Thanks
23rd Jul 2025, 3:30 PM
Alban
Alban - avatar
+ 3
U may also use switch statement that is easy to understand and write
24th Jul 2025, 6:53 PM
krishma mahajan
krishma mahajan - avatar
+ 2
The code has minor error you need to write return 0; line below if statement and in if statement you need to add common brackets inside the condition Like this below #include <iostream> using namespace std; int main() { int points; cin>>points; cout << points; if (points<20) { cout << "Tu as rouge."<<endl; } return 0; }
23rd Jul 2025, 11:43 AM
Aysha
+ 2
Ok thanks guys
23rd Jul 2025, 12:48 PM
Alban
Alban - avatar
+ 2
Please I got another problem and I don't understand it
23rd Jul 2025, 2:17 PM
Alban
Alban - avatar
+ 2
Alban you can give range in switch statement too so less error. Check out the link below for understanding how it works https://www.geeksforgeeks.org/cpp/using-range-in-cpp-switch-case/
24th Jul 2025, 8:27 PM
Aysha
+ 2
Ok I will do it
24th Jul 2025, 8:36 PM
Alban
Alban - avatar
+ 1
What did he said ?
23rd Jul 2025, 5:00 PM
Alban
Alban - avatar
+ 1
No because I have to say case 1,case 2 and do it untik I reach 100 so it is way more dificult to read and I will make more mistakes
24th Jul 2025, 7:11 PM
Alban
Alban - avatar
+ 1
Aysha, Alban while using range in switch-case works here in Sololearn, you should be aware that it's a compiler dependent feature. it does not work for non-GCC compilers, so you should test it and be aware that it's a GCC extension and might not work if your code happens to be compiled with other compilers...
24th Jul 2025, 10:47 PM
Bob_Li
Bob_Li - avatar
+ 1
Ok
25th Jul 2025, 6:09 AM
Alban
Alban - avatar