We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Classes
- Classes and Objects
- Discussions
Classes and Objects
Classes and Objects
Sort by
recency
|
414 Discussions
|
Please Login in order to post a comment
include
using namespace std; class Student{ private: int q1,q2,q3,q4,q5; public: void input(){ cin >> q1 >> q2 >> q3 >> q4 >> q5; } int calculateTotalScore(){ int score; score += q1+q2+q3+q4+q5; return score; }}; int main() { int n; // number of students cin >> n; Student *s = new Student[n]; for(int i = 0; i < n; i++){ s[i].input(); } int kristen_score = s[0].calculateTotalScore(); int count = 0; for(int i = 1; i < n; i++){ int total = s[i].calculateTotalScore(); if(total > kristen_score){ count++; } } cout << count; return 0; }Mine wors in my compiler, but when I put the exact same code in the Hackerank compiler, it gives me the wrong answer. Very bizarre:
No locked code int C++20
That i lost time implementing the parsing and the reading. Fix that shit