My program should fill up and show an array. It should also calculate average value in the array.
The program stops at this line:
cin >> *f1[j];
I think it's the problem line, but I could have made mistakes elsewhere.
#include <iostream>
using namespace std;
// prototypes
void add(int*f[],int h);
void show(int*f[],int h);
int average(int*f[],int h);
int main()
{
// getting size of a array
cout << "How many numbers would you insert? : ";
int i = 0;
cin >> i;
cout << endl;
// the dinamic array
int * arr = new int[i];
// call functions
add(&arr, i);
show(&arr, i);
average(&arr, i);
// deleting the dinamic array
delete[] arr;
system("pause");
return 0;
}
// declaring of the functions
// this function should fill up the array
void add(int* f1[], int h)
{
for(int j = 0 ; j < h ; j++)
{
cout << "Insert " << j+1 << ". value : ";
cin >> *f1[j]; //this should be the problem
cout << endl;
}
}
// this function should show the array
void show(int *f2[], int h)
{
for(int j = 0 ; j < h ; j++)
{
cout << *f2[j] << ", ";
}
}
// this function should should show average value of the array
int average(int *f3[], int h)
{
int n = 0;
for(int j = 0 ; j < h ; j++)
{
n += *f3[j];
}
n /= h;
return n;
}
You'll need to:
int* fX
in your function signatures&
referencing from your function calls (you already have a memory address stored in arr
and there's no such thing as a memory address for another memory address)*
dereferencing within your functions (you're already dereferencing the array with []
indexing)http://pastebin.com/xY7A6JvE compiles and runs.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments