Advertisement
JOHNYTHEWINNER

Odd/Even - do/while

Feb 2nd, 2020
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 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 n;
  10.     cin >> n;
  11.     int scoreeven = 0;
  12.     int scoreodd = 0;
  13.     int temp;
  14.     int i = 0;
  15.     do
  16.     {
  17.         cin >> temp;
  18.         if (i % 2 == 0)
  19.         {
  20.             scoreeven += temp;
  21.         }
  22.         else
  23.         {
  24.             scoreodd += temp;
  25.         }
  26.         i += 1;
  27.     } while (i <= n-1);
  28.     if (scoreeven != scoreodd)
  29.     {
  30.         cout << "No" << endl;
  31.         cout << "Diff = " << abs(scoreeven - scoreodd) << endl;
  32.     }
  33.     else
  34.     {
  35.         cout << "Yes" << endl;
  36.         cout << "Sum = " << scoreeven << endl;
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement