program stops running (program in conditional and repetitive statements)

what is the error in this equation's program?
it has no errors when compiling but it stops while running
after I input the values of x ,m , and n

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
  #include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int i=1,m,j,z=1;
    float s1,s2,s,x;
    cout<<"Enter the value of x"<<endl;
    cin>>x;
    cout<<"Enter the integer value of M"<<endl;
    cin>>m;
    cout<<"Enter the integer value of N"<<endl;
    cin>>j;


        for(i;i<m+1;++i)
        {
            int h=2*i;
            if(h>1)
            {
            z=z*h;
             --h;
            }
            x=x*3;
        s1=pow((x+6),h)*(pow(z,-1));
        }

    for(j;j<6;++j)
    {
        if(j>1)
        { z=z*j;
         --j;}
        s2=(pow((x+1),j))*pow(z,-1);
    }
    s=1+s1+s2;
    cout<<"S = "<<s<<endl;


    return 0;
}


And no I can't use structures ,classes or functions the tutor does not allow us to .
yamada,

I think it would be a good idea if you told us what equation you were actually trying to encode. I'm afraid that we aren't mindreaders. Your programming is so contorted that it is very difficult to see what you intended.

But look at a few things.

Your loop header:
for(i;i<m+1;++i)
The first item ought to be setting a value of i (or just left blank). What were you intending?
Similarly for the j loop.

Your j loop has a ++j in the header and a --j inside. Do you think this is likely?

What do you think pow(z,-1) is? I think most people would regard it as 1/z. Actually, most people would regard
*pow(z,-1)
as being equivalent to
/z

If you ask the user for a value of N ... and then enter it into a variable called j ... this is a recipe for confusion.

Please provide a statement of what you are trying to do, and have another look at your code. Then post a revision for us to look at.
lastchance,

I apologize, I didn't notice the codes that allow me to write it the equation like this^^"
This is the equation

S=1+∑Mi=1((3x+6i)2i/(2i)!)+∑5j=N((x+1)j/(j!))

About the conditional loop i though it would result in an error if any were left blanck ^^" thanks for explaining :)
And the pow (j,-1) for example that's in order to get both integer and remainder values of division operation so i'd have exact values.
As for the --j that was to get the factorial of j
Not being allowed to use any functions or classes had me really confused in how do I write this equation properly
Last edited on
S=1+∑Mi=1((3x+6i)2i/(2i)!)+∑5j=N((x+1)j/(j!))

What? It is so complex!
What is your assignment all about?
Tencacle,

I know it is ^^"
Conditional and Repetitive Statements Algorithim class
What is your current problem now?
Now the program works correctly with accurate results :D
Thanks for the advice ^^
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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int i,m,j,n,h,z;
    float s1=0,s2=0,s,x;
    cout<<"Enter the value of x"<<endl;
    cin>>x;
    cout<<"Enter the integer value of M"<<endl;
    cin>>m;
    cout<<"Enter the integer value of N"<<endl;
    cin>>n;


        for(i=1;i<(m+1);++i)
        {
             h=2*i;
             z=1;
            while(h>1)
            {
            z=z*h;
             --h;
            }
        s1+=pow((3*x+6),(2*i))*pow(z,-1);
        }

    for(j=n;j<6;++j)
    {
        h=j;
        z=1;
        while(h>1)
        {
            z=z*h;
         --h;}

        s2+=pow((x+1),j)*pow(z,-1);

    }
    s=1+s1+s2;
    cout<<"S = "<<s<<endl;


    return 0;
}
CarolStar,
no more problems ^^ thank you ^^
Topic archived. No new replies allowed.