+ 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; }
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;
}
+ 2
That means if we take int mark = 30 then it will show fail 🤣
+ 2
Yeah, exactly. :D You're welcome.
+ 1
Thx