Problems with functions

I need to find x, y, sum and modulus of difference between y and sum using functions. But the program does not calculate the functions. Here is my code:

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
#include <iostream>
#include <cstdlib>
#include "math.h"
using namespace std;
int findX(double x, double sum, int r, int k, double a, double b, double h, double n);
int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y);
int findSum(double x, double sum, int r, int k, double a, double b, double h, double n);
int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y);
int main()
{
    double a, b, x, h, r, sum, y, mod;
    int n, k;
    cout<<"Input a = ";
    cin>>a;
    cout<<"Input b = ";
    cin>>b;
    cout<<"Input h = ";
    cin>>h;
    cout<<"Input n = ";
    cin>>n;
    cout<<endl;
    int findX(double x, double sum, int r, int k, double a, double b, double h, double n);
    int findSum(double x, double sum, int r, int k, double a, double b, double h, double n);
    int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y);
    int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y);
    system("pause");
}
    int findX(double x, double sum, int r, int k, double a, double b, double h, double n)
    {
       for(x = a; x<=b; x+=h)
         {
           r = sum = 1;
           for(k = 1; k<=n; k++)
               {
                r=2*r*x/k;
                sum+=r;
                   cout<<"x = "<<x<<endl;
               }
         }
        return x;
    }
    int findSum(double x, double sum, int r, int k, double a, double b, double h, double n)
    {
        for(x = a; x<=b; x+=h)
           {
            r = sum = 1;
            for(k = 1; k<=n; k++)
               {
                r=2*r*x/k;
                sum+=r;
                cout<< "Sum = "<<sum<<endl;
               }
            }
        return sum;
    }
    int findY(double x, double sum, int r, int k, double a, double b, double h, double n, double y)
        {
        y=pow(exp(x),2*x);
        cout<<"Y = "<<y<<endl;
        return y;
        }
    int findMod(double x, double sum, int r, int k, double a, double b, double h, double n, double mod, double y)
        {
        mod=fabs(y-sum);
        cout<<"|Y(x)-Sum(x)| = "<<mod<<endl;
            return sum;
        }
Last edited on
Lines 22-25 are function declarations, not function calls.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thank you for the hint! But how can I correct this?
int result = findX(somevariable, 12, 5, anothervariable, ... etc.. );
you call it with values you have (variables, constants, etc) and put the result into a variable or use it directly (such as cout << findX(...stuff) << ) but usually you will store the result in a variable.

notice no types when it is CALLED, and the variables and constants don't have to name-match the parameters.

a smaller simpler example...
int sum(int a, int b)
{
return a+b;
}

...
z = sum(1,2);
x = sum(3,4);
y = sum(z,x);

like that.
Last edited on
Topic archived. No new replies allowed.