Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Exam Preparation - getline trouble

JOHNYTHEWINNER Feb 10th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top