Advertisement
Guest User

Untitled

a guest
Aug 8th, 2014
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // prototypes
  6. void add(int* f,int h);      
  7. void show(int* f,int h);
  8. int average(int* f,int h);
  9.  
  10. int main()
  11. {
  12.     // getting size of a array
  13.     cout << "How many numbers would you insert? : ";
  14.     int i = 0;
  15.     cin >> i;
  16.     cout << endl;
  17.  
  18.     // the dinamic array
  19.     int* arr = new int[i];
  20.  
  21.     // call functions
  22.     add(arr, i);
  23.     show(arr, i);
  24.     average(arr, i);
  25.  
  26.     // deleting the dinamic array
  27.     delete[] arr;
  28.     system("pause");
  29.     return 0;
  30. }
  31.  
  32. // declaring of the functions
  33.  
  34. // this function should fill up the array
  35. void add(int* f1, int h)
  36. {
  37.     for(int j = 0 ; j < h ; j++)
  38.     {
  39.         cout << "Insert " << j+1 << ". value : ";
  40.         cin >> f1[j]; //this should be the problem
  41.         cout << endl;
  42.     }
  43.  
  44. }
  45.  
  46. // this function should show the array
  47. void show(int* f2, int h)
  48. {
  49.     for(int j = 0 ; j < h ; j++)
  50.     {
  51.         cout << f2[j] << ", ";
  52.     }
  53. }
  54.  
  55. // this function should should show average value of the array
  56. int average(int* f3, int h)
  57. {
  58.     int n = 0;
  59.     for(int j = 0 ; j < h ; j++)
  60.     {
  61.         n += f3[j];
  62.     }
  63.     n /= h;
  64.     return n;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement