Phoenix_x

Untitled

Nov 29th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5. void enterData(int numbers[], int &size);
  6.  
  7. void main()
  8. {
  9.     int numbers[18];
  10.     int size = 0;
  11.  
  12.     while (true)
  13.     {
  14.         int option;
  15.         cout << "Izberi 1 za vavezdane na razmernost i chisla" << endl;
  16.         cout << "Izberi 2 za namirane na proizvedenie ot polozitelni chisla v daden interval" << endl;
  17.         cin >> option;
  18.  
  19.         switch (option)
  20.         {
  21.         case 1:
  22.             enterData(numbers, size);
  23.             break;
  24.         case 2:
  25.             multiplicationInRange(numbers, size);
  26.             break;
  27.  
  28.         default:
  29.             cout << "Nevaliden vhod" << endl;
  30.         }
  31.     }
  32. }
  33.  
  34. void enterData(int numbers[], int &size)
  35. {
  36.     cout << "Broj chisla: ";
  37.     cin >> size;
  38.  
  39.     while (size < 0 || size > 18)
  40.     {
  41.         cout << "Nevaliden razmer!" << endl;
  42.         cout << "Vavedi razmer otnovo: ";
  43.         cin >> size;
  44.     }
  45.  
  46.  
  47.     for (int i = 0; i < size; i++)
  48.     {
  49.         cin >> numbers[i];
  50.     }
  51. }
  52.  
  53. void multiplicationInRange(int numbers[], int size)
  54. {
  55.     int min;
  56.     cout << "Min: ";
  57.     cin >> min;
  58.  
  59.     int max;
  60.     cout << "Max: ";
  61.     cin >> max;
  62.  
  63.     int multiply = 1;
  64.  
  65.     for (int i = 0; i < size; i++)
  66.     {
  67.         if (numbers[i] >= min && numbers[i] <= max && numbers[i] > 0)
  68.         {
  69.             multiply *= numbers[i];
  70.         }
  71.     }
  72.  
  73.     cout << "Proizvedenie: " << multiply << endl;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment