Advertisement
JOHNYTHEWINNER

Exam Preparation - getline trouble

Feb 10th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. # include <iostream>
  2. using namespace std;
  3. #include <iomanip>
  4. #include <math.h>
  5. #include <cmath>
  6. #include <string>
  7. int main()
  8. {
  9.     int badtries;
  10.     cin >> badtries;
  11.     int tempscore;
  12.     string lastname;
  13.     string name;
  14.     int tries = 0;
  15.     int badscore = 0;
  16.     double sum = 0;
  17.     while (badscore < badtries) {
  18.         getline(cin, name);
  19.         getline(cin, name);
  20.         if (name == "Enough") {
  21.             cout << "Average score: " << fixed << setprecision(2) << sum / tries << endl;
  22.             cout << "Number of problems: " << tries << endl;
  23.             cout << "Last problem: " << lastname << endl;
  24.             break;
  25.         }
  26.         lastname = name;
  27.         cin >> tempscore;
  28.         if (tempscore <= 4) {
  29.             badscore += 1;
  30.         }
  31.         if (badscore >= badtries) {
  32.             cout << "You need a break, " << badscore << " poor grades." << endl;
  33.         }
  34.         tries++;
  35.         sum += tempscore;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement