Advertisement
axyd

Lab 6, part 2

May 1st, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void Sums(int, int&, int&, int&);
  5.  
  6. int main(){
  7.     int N, o1 = 0, o2 = 0, o3 = 0;
  8.     char again = 'y';
  9.  
  10.     while (again == 'y' || again == 'Y'){
  11.         cout << "Please input a number and i calculate 3 sums: ";
  12.         cin >> N;
  13.  
  14.         Sums(N, o1, o2, o3);
  15.  
  16.         cout << "1 to N is : " << o1
  17.             << "\nN+23 to N+200 is: " << o2
  18.             << "\n2N to 5n is: " << o3 << endl << endl;
  19.  
  20.         cout << " Do you want to continue (y|Y)?: ";
  21.         cin >> again;
  22.     }
  23. }
  24.  
  25. void Sums(int in, int& _1_N, int& n23_100, int& _2n_5n){
  26.     _1_N = 0, n23_100 = 0, _2n_5n = 0; //reinitialize
  27.     int n23 = (in + 23), n100 = (in + 100), N2 = (in*2), N5= (in*5);
  28.    
  29.     for (int ctr = 1; ctr <= in; ctr++)
  30.         _1_N += ctr;
  31.  
  32.     for (int ctr2 = n23; ctr2 <= n100; ctr2++)
  33.         n23_100 += ctr2;
  34.  
  35.     for (int ctr3 = N2; ctr3 <= N5; ctr3++)
  36.         _2n_5n += ctr3;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement