wigllytest

Untitled

Aug 8th, 2020
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main() {
  9.  
  10. int limitBadGrades;
  11. cin >> limitBadGrades;
  12. cin.ignore();
  13.  
  14.  
  15. string problemName;
  16. getline(cin >> ws, problemName);
  17. int gradeSum = 0;
  18. int gradeCount = 0;
  19. string lastProblemName = "";
  20. int badGradesCounter = 0;
  21.  
  22. while (problemName != "Enough")
  23. {
  24. int grade;
  25. cin >> grade;
  26. cin.ignore();
  27.  
  28. gradeSum += grade;
  29. gradeCount++;
  30. lastProblemName = problemName;
  31.  
  32. if (grade <= 4)
  33. {
  34. badGradesCounter++;
  35. }
  36. if (badGradesCounter == limitBadGrades)
  37. {
  38. break;
  39. }
  40.  
  41. getline(cin, problemName);
  42. }
  43.  
  44. if (problemName == "Enough")
  45. {
  46. cout.setf(ios::fixed);
  47. cout.precision(2);
  48.  
  49. double averageGrade = gradeSum * 1.0 / gradeCount;
  50. cout << "Average score: " << averageGrade << endl;
  51. cout << "Number of problems: " << gradeCount << endl;
  52. cout << "Last problem: " << lastProblemName;
  53. }
  54.  
  55. if (badGradesCounter == limitBadGrades)
  56. {
  57. cout << "You need a break, " << badGradesCounter << " poor grades.";
  58. }
  59.  
  60.  
  61. return 0;
  62. }
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment