0
What is wrong with that code please help me I can't figure out
https://sololearn.com/compiler-playground/cwHaCiEelzQ6/?ref=app
10 Respuestas
0
What did he said ?
+ 4
Bhushan kale keep your language clean on Sololearn. Personal attacks are unacceptable and will get your account banned.
+ 3
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
+ 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;}
+ 2
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
}
+ 2
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 =<.
+ 1
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;
}
+ 1
Please I got another problem and I don't understand it
+ 1
Thanks
0
Ok thanks guys