Function not calculating

Hi! I have written a code, which calculates x, y, sum and module of difference between y and sum with the help of functions. The result of function y must change depending on the value of x. But for some reason, with different values of x the value of y stays the same and equals 1. How can I change it? Thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  //---------------------------------------------------------------------------
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
//---------------------------------------------------------------------------
typedef double(*TY)(double);
typedef double(*TSum)(double,int);
typedef double(*TMod)(TY,TSum, double,int);
double Y(double);
double Sum(double,int);
double Mod(TY,TSum, double,int);
void Out_Rez1(TY,double,double,double);
void Out_Rez2(TSum,double,double,double,int);
void Out_Rez3(TMod,double,double,double,int);
int main()
{
    double a,b,h,x;
    int n;
    cout<<"Input a = ";
    cin>>a;
    cout<<"Input b = ";
    cin>>b;
    cout<<"Input h = ";
    cin>>h;
    cout<<"Input n = ";
    cin>>n;
    cout<<endl;
    cout<<"Function - Y(x): "<<endl;
    Out_Rez1(Y,a,b,h);
    cout<<"Function - Sum: "<<endl;
    Out_Rez2(Sum,a,b,h,n);
    cout<< "Function - |Y(x)-Sum(x)|: "<<endl;
    Out_Rez3(Mod,a,b,h,n);
    system ("pause");
}
double Y(double x)
{
    double Y;
    Y=pow(exp(x),2*x);
    return Y;
}
double Sum(double x, int n)
{
    int k;
    double r,Sum;
    r=Sum=x;
    for (k=1; k<=n; ++k)
    {
        r=2*r*x/k;
        Sum+=r;
    }
    return Sum;
}
double Mod(TY Y,TSum Sum, double x, int n)
{
    return fabs(Y(x) - Sum(x,n));
}
void Out_Rez1(TY Y, double a, double b, double h)
{
    for(double x=a; x<=b; x+=h)
    {
        cout<<"x="<<x<<"  ";
        cout<<"Y="<<Y<<" "<<endl;
        cout<<endl;
    }
}
void Out_Rez2(TSum Sum, double a, double b, double h, int n)
{
    for(double x=a; x<=b; x+=h)
        cout<<"Sum = "<<x<<Sum(x,n)<<" "<<endl;
    cout<<endl;
}
void Out_Rez3(TMod Mod, double a, double b, double h,int n)
{
    for(double x=a; x<=b; x+=h)
        cout<<"Mod = "<<x<<Mod(Y,Sum,x,n)<<" "<<endl;
    cout<<endl;
}

//---------------------------------------------------------------------------

x is uninitialized. It may be zero in a debug mode compiler.
Y(x) is therefore junk, which may or may not be == to 1.
Topic archived. No new replies allowed.