Why we are getting only pass result not fail 🤣. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Why we are getting only pass result not fail 🤣.

include <iostream> using namespace std; int main() { int mark = 90; if (mark < 50) { cout << "You failed." << endl; } else { cout << "You passed." << endl; } return 0; }

17th May 2019, 4:44 PM
Ravi Henry
Ravi Henry - avatar
4 Antworten
+ 4
Because you hardcoded the value of mark, so it's always 90. According to your logic in the lower half, anything that is 50 or above is passing, so 90 is always passing. This code will use cin (console input) to store user's input into the variable 'mark' so you can specify the grade at execution and test your various conditions. https://code.sololearn.com/cqYQc588Gl0Q/#cpp #include <iostream> using namespace std; int main() { int mark; cout << "Please enter grade: \n"; cin >> mark; if (mark < 50) { cout << "You failed." << endl; } else { cout << "You passed." << endl; } return 0; }
17th May 2019, 4:50 PM
AgentSmith
+ 2
That means if we take int mark = 30 then it will show fail 🤣
17th May 2019, 4:52 PM
Ravi Henry
Ravi Henry - avatar
+ 2
Yeah, exactly. :D You're welcome.
17th May 2019, 5:02 PM
AgentSmith
+ 1
Thx
17th May 2019, 4:54 PM
Ravi Henry
Ravi Henry - avatar