Thread: Please Help~~!

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    3

    Please Help~~!

    Code:
    # include <FPT.h> // finding mean and standard deviation
    int main()
    
    {double d[1000],s,x,n,z,m,i,c;
    
      outS("enter the numbers: ");
    
     x=inD();n=0;
    
     if(x<0){outS("no data");outS("\n");exit(0);}
    
     while(x>=0){
    
       d[n]=x;
    
       s=s+x;
    
       n=n+1;
    
       x=inD();
    
     }
    
     m=s/n;
    
     outS("This is the Mean: ");outD(m);outS("\n");
    
     i=0;z=0;
    
     while(i>n);{z=z+(d[i]-m)*(d[i]-m);i=i+1;}
    
     outS("This is the Standard Deviation: ");outD(sqrt(z/n));outS("\n");
    
    }

    I am trying to find the mean and standard deviation of entered numbers. But the standard deviation part does not work as I expected. Please, please help me. Thanks a lot.

    PS: I am new to C language, our professor only taught us how to program by using this kind of language and I couldn't find any reference information by looking around on the Internet. It's kind of different from what people would always use in C. Does anyone know any book or reference site I can go to get a better understanding of this language? Thanks a ton.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    {double d[1000],s,x,n,z,m,i,c;
    None of these have any specific values when you declare them here. They just have whatever random number happened to be in the spot in memory when they were created. Thus:
    Code:
     while(x>=0){
    
       d[n]=x;
    
       s=s+x;
    This adds x to whatever random value s had there. You need to initialize all of your variables before you use them.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Than you for replying.

    I got the summation and mean part with no problem.

    d[n]=x, is to record the input x as elements of the d[n] array.

    I just do not know how to create another loop to sum the array up. Could you please help me with that?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Keep track of n. When you're done looping, loop from 0 to one less than n (assuming n is one more than how ever many things you have stored), and add them up:
    Code:
    for( x = 0; x < n; x++ )
        sum = sum + this spot in the array;
    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    I am sorry, but I do not understand your code...

    As mentioned, our professor only taught us how to write the code in a strange fashion.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Pay a visit to these two guys, the link in my first reply should cover the use of the for loop.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help~!~
    By cude87 in forum C++ Programming
    Replies: 16
    Last Post: 10-02-2004, 05:55 PM
  2. Help~~
    By joy in forum C++ Programming
    Replies: 6
    Last Post: 11-24-2001, 07:59 AM

Tags for this Thread