sqrt of the sum of array Z

sqrt of the sum of array Z

Page 1 of 1

1 Replies - 2041 Views - Last Post: 05 December 2006 - 02:44 PM Rate Topic: -----

#1 JulietLdy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-November 06

sqrt of the sum of array Z

Posted 05 December 2006 - 12:22 PM

I am trying to print out the square root of the sum of array Z and I am trying to print out the values of z[i] that are above the average of array z. It will not work. Please help. The following is the code that I have so far. The error message for sqrt says "ambiguous call to overloaded function". Also, how do i go about finding the min value for each array x,y,and z with only using one function? Please help thank you.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>

using namespace std;
void readdata(ifstream &fx, int abc[], int &ct);

void main()
{ int x[20] = {0}, y[20] = {0}, z[20] = {0};
  int ctx = 0, cty =0, ctz=0, sumz=0;
  double averagez=0, sqrtz=0;
  cout<<setiosflags(ios::fixed | ios::showpoint)
	  <<setprecision(2);
  ifstream f1 ("h:\\datax.txt",ios::in);
  ifstream f2 ("h:\\datay.txt",ios::in);

  readdata(f1,x,ctx);
  readdata(f2,y,cty);

  f1.close();
  f2.close();

  
		
		cout<<setw(5)<<"X"<<setw(5)<<"Y"<<setw(5)<<"Z"<<endl;
	for(int i=0; i<20; i++)
	{
	  z[i]=x[i]*y[i];
		ctz++;
		cout<<"\n\n";
		cout<<setw(5)<<x[i]<<setw(5)<<y[i]<<setw(5)<<z[i]<<endl;
		
		cout<<"\n\n\n";

	}
	int sum;
		for(int i=0; i<20; i++)
		{
			sumz+=z[i];
		cout<<"The sum of column Z = "<<sumz<<endl;
		}

	
	cout<<"\n\n";

	int average;
		for(int i=0; i<20; i++)
		{
			averagez=sumz/ctz;
			
		cout<<"The average of column Z is = "<<averagez<<"\n\n";
		}

	if(z[i]>averagez)
		cout<<z[i]<<endl;

	sqrtz=sqrt(sumz);
	cout<<sqrtz<<endl;


	


	

		
		
	
}
  void readdata(ifstream &fx, int abc[], int &ct)
  {
	 ct = 0; cout<<"\n\n";
	   while (fx>>abc[ct], !fx.eof())
	   {   
			ct++;
	}
	
   }
  


This post has been edited by JulietLdy: 05 December 2006 - 12:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: sqrt of the sum of array Z

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 291
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: sqrt of the sum of array Z

Posted 05 December 2006 - 02:44 PM

the problem with
	sqrtz=sqrt(sumz);


is because sumz is defined as an int - make it a double and you should be OK (some compilers have float and double versions of sqrt() and don't know which to use for an int parameter)

This post has been edited by horace: 05 December 2006 - 02:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1