I am trying to write a program that repeatedly asks you to enter pairs of numbers until at least one of the pair is zero. For each pair, the program should use a function to calculate the harmonic mean of the numbers the function should report the result. This is the code I have done but I am not sure I am on the right track. I just can't seem to get the right things together.
#include <iostream.h>
const int ArSize = 2;
int fill_array(int ar[], int n);
double hmean(double x, double y);
int main(void)
{
int numbers[ArSize];
cout << "Please enter a pair of numbers\n";
cout << "\t(q to quit)\n\n";
int total = fill_array(int ar[], int n);
hmean(total, numbers);
cin.get();
return 0;
}
int fill_array(int ar[], int n)
{
int numbers;
for (int i = 0; i < n; i++)
{
cout << "Enter pairs #" << (i + 1) << ": ";
while (!(cin >> numbers))
{
if (i==0)
break;
return 0;
}
ar[i] = numbers;
}
return i;
}
double hmean(int ar[], int n)
{ int x,y = 0;
for (int i = 0; i < n; i++)
{
return ar[i] = 2*x*y/(x+y);
}
}



LinkBack URL
About LinkBacks



