Did the Average Pass?
0.5s 256MMing took \(n\) subjects this semester, and his total score is \(total\). The teacher says that he passes only if his average score is at least \(60\). Determine whether Ming passes this semester.
When \(n > 0\), the average score is computed using integer division, so the decimal part is discarded.
Note that if \(n\) is \(0\), he has not taken any subject yet, so there is no average score. In this case, he is considered not passing. In this case, \(total\) is guaranteed to be \(0\).
Ming tried to write the following program, but it contains a mistake. Think about what is wrong with it, then write a correct program.
#include <iostream>
using namespace std;
int main() {
int total, n;
cin >> total >> n;
if (total / n >= 60 && n != 0) cout << "Pass" << endl;
else cout << "Fail" << endl;
return 0;
}
Input
The input contains one line with two integers \(total\) and \(n\), separated by a space.
Constraints
- \(0 \le total \le 10000\)
- \(0 \le n \le 100\)
- If \(n = 0\), then \(total = 0\)
Output
If Ming passes, output Pass; otherwise, output Fail.
Sample Input 1
180 3
Sample Output 1
Pass
Sample Explanation 1
The average score is \(60\), so it reaches the passing standard.
Sample Input 2
179 3
Sample Output 2
Fail
Sample Explanation 2
The average score is computed using integer division: \(179 / 3 = 59\), which is less than \(60\).
Sample Input 3
0 0
Sample Output 3
Fail
Sample Explanation 3
\(n = 0\) means no subject has been taken yet, so there is no average score and Ming is considered not passing.
Log in to write and submit code. Creating an account is free.