Thread: return value for protype

  1. #16
    Registered User
    Join Date
    Nov 2012
    Posts
    9
    guys this is running but i need to give the value for the count.which i dont want to happen.Plzzzzzzzzzzzz look at it
    Code:
    #include <iostream>
    #include<cmath>
    using namespace std;
    int zahl( double , double x[], double );
    int main (void)
    {
    
    int ncount=10,i;
    double a[ncount];
    double subject,epsilon,newepsilon;//,newepsilon;
      cout<<"Please input a postive real number:";
      cin>>subject;
      cout<<"Please input a postive real value for the relative accuracy epsilon:";
      cin>>epsilon;
            ncount = zahl (subject, a, epsilon);
    //  cout<<"count="<<ncount<<endl;
    double x[ncount];
    x[0]=subject/2.0;
    cout<<"Value\t\tRelative Accuracy"<<endl;
    cout<<"x[0]="<<x[0]<<endl;
        for(i=0;i<ncount;i++)
        {
            x[i+1]=((x[i] +(subject/x[i]))/2.0);
            newepsilon=((x[i+1]-x[i])/x[i+1]);
            cout<<"x["<<i+1<<"]="<<x[i+1]<<"\t\t"<<abs(newepsilon)<<endl;
    
        }
    
    }
    int zahl ( double subject,double x[], double epsilon)
    {
        x[0]=subject/2.0;
        int n=0;
        double newepsilon;
        x[n+1]=((x[n] +(subject/x[n]))/2);
        newepsilon=((x[n+1]-x[n])/x[n+1]);
        int count=10;
            while(newepsilon > epsilon)
            {
                x[n+1]=((x[n] +(subject/x[n]))/2);
                newepsilon=((x[n+1]-x[n])/x[n+1]);
                newepsilon=abs(newepsilon);
                count=count+1;
            }
    return count;
    }

  2. #17
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Yes it is.If you want not to set it manually you can read it from stdin, with cin and then declare the array. Why you are not happy with the code ?

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You still need to fix your indentation.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reson behind following strcpy protype
    By sanddune008 in forum C Programming
    Replies: 4
    Last Post: 03-13-2012, 05:39 AM
  2. Replies: 1
    Last Post: 07-04-2007, 12:20 AM
  3. Replies: 12
    Last Post: 04-07-2007, 11:11 AM
  4. Replies: 6
    Last Post: 04-09-2006, 04:32 PM
  5. Replies: 4
    Last Post: 07-15-2005, 04:10 PM

Tags for this Thread