473,320 Members | 1,691 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

array , functions

hi again ..

well i do write the code but it doesnt work
i really dont what to do ?

this is my code

#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

void generate (int x[],int n);
void statistic (int x[],int n,double& m,double& d);
void result (double& m, double& d);

int main()
{
//declar the variables

int x[10];
double m,d;
int n=10;


//call functions

generate(x,n);
statistic(x,n,m,d);
result(m,d);
return 0;
}

// end of main

void generate (int x[],int n)// the function no.1

{
for(int i =1;i<10;i++) //using for loop
{

x[i]= (rand()%(15-5+1))+5;
cout<<x[i]; // cout the array
cout<<endl;
}

}

void statistics (int x[],int n,double & m,double & d)
{
int sum=0;
int i;
int z;
for(i=0;i<n;i++)

{
sum=sum+x[i];

}

m = 1.0*sum/n;

z=pow(x[i]-m,2);

d=sqrt(z)/n;
}
void result (double& m,double& d) // the output of m&d
{
cout<<"The mean value is: "<< m <<endl;
cout<<"The standard deviation is :"<<d<<endl;

}

Apr 26 '07 #1
2 1896
tea-jay schreef:
hi again ..

well i do write the code but it doesnt work
i really dont what to do ?

this is my code

#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;

void generate (int x[],int n);
void statistic (int x[],int n,double& m,double& d);
void result (double& m, double& d);

int main()
{
//declar the variables

int x[10];
double m,d;
int n=10;


//call functions

generate(x,n);
statistic(x,n,m,d);
result(m,d);
return 0;
}

// end of main

void generate (int x[],int n)// the function no.1

{
for(int i =1;i<10;i++) //using for loop
for (int i = 0; ...
{

x[i]= (rand()%(15-5+1))+5;
cout<<x[i]; // cout the array
cout<<endl;
}

}

void statistics (int x[],int n,double & m,double & d)
{
int sum=0;
int i;
int z;
for(i=0;i<n;i++)

{
sum=sum+x[i];

}

m = 1.0*sum/n;

z=pow(x[i]-m,2);

d=sqrt(z)/n;
}
void statistics (int x[],int n,double & m,double & d)
{
int sum = 0, sum2 = 0;

for(int i=0;i<n;i++)
}
sum += x[i];
sum2 += x[i]*x[i];
}
m = sum/n;

// for std deviation: mean[(x-m)^2] = mean[x^2 - 2mx +m^2]
// = mean(x^2) - 2m mean[x] + m^2 //** mean[x] = m
// = mean(x^2) - m^2

d = sqrt(sum2/n - m*m);
}
>

void result (double& m,double& d) // the output of m&d
{
cout<<"The mean value is: "<< m <<endl;
cout<<"The standard deviation is :"<<d<<endl;

}
Apr 26 '07 #2
tea-jay <ta******@hotmail.comwrites:
>hi again ..
>well i do write the code but it doesnt work
You mean it doesn't compile?
>void statistic (int x[],int n,double& m,double& d);
....
> statistic(x,n,m,d);
....
>void statistics (int x[],int n,double & m,double & d)

You have statistic and statistics mixed up.
Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
4
by: Mark Hannon | last post by:
I am trying to initialize an array only once so it can be seen & used by any functions that need it. As I understand it, if a variable is declared by itself outside of any functions, its scope is...
32
by: Carson | last post by:
Hi , Is there a very efficient way to set a double array to 0 ? (I have tried memset, but the result doesn't look correct.) Carson
5
by: Steve | last post by:
Can anyone tell me if I can have an array of functions that take a variable number of parameters? If it is possible I'd like to know how to declare the array and the functions as its elements. I am...
7
by: arkobose | last post by:
hey everyone! i have this little problem. consider the following declaration: char *array = {"wilson", "string of any size", "etc", "input"}; this is a common data structure used to store...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
9
by: JoeC | last post by:
I am crating a new version of my map game and my map will be a 2d array. I had problems trying to create a 2d array dynamically, in fact C++ won't let me do it. My question is how to create the...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
3
by: David K in San Jose | last post by:
I'm using managed (CLR) C++ in VS2005 to create a Windows app that contains a form named "MyForm". In the code for that form I'm trying to invoke some static functions by using an array of function...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.