factorial

Ok so I am having trouble with my initial declaration of my factorial statement for my final output can anyone help me out? there are a couple other things but i think through fiddling i am able to figure it out.


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
 using namespace; std;
#include <iomanip>
#include <iostream>

long factorial (int x)   // defining the factorial equation
{
    if (x<=0)
    {
        return -1;
    }
        int z, fact=1;
    for(z=1; z <= x; z++)
    {
        fact=fact*z;
    }
}
int main(void)
{
    long factorial(int x);
    double minimum, maximum, step; //making the variables
    double count = 0;
    float Rate;
    step=0;
    
    cout << "Enter the minimum: \n";
    cin >> minimum;
    cout << "Enter the maximum: \n";
    cin >> maximum;
    cout << "Enter the step rate: \n";
    cin >> step;
    while(count != 2)
    {
        if((minimum<0||maximum<minimum||maximum<0||step<=0)) //giving the parameters to be computed
        {
            double y;//number of attempts allowed
            minimum=0;
            maximum=0;
            step=0;
            cout << "You either entered a negative number or your maximum is lower than your minimum, please correct this error\n" << endl;
            cout << "Enter the minimum: \n";
         			cin >> minimum;
            cout << "Enter the maximum: \n";
            cin >> maximum;
            cout << "Enter the step rate: \n";
            cin >> step;
            count++, y++;
            if(y = 2)
            {
                return 0;
            }
        }
        else
        {
            count++;
        }
    }
    cout << "\n x    x-factorial\n";  // this is just writing it out for your formatting purposes
    cout << " ----    ----------\n";
    for(x=minimum; x<=maximum; x+=step)
        {
            long factorial(x)
            cout << setw(8) << x << setw(15) << factorial(x) << endl; //spacing for output
        }
    return 0;
    }
}
closed account (SECMoG1T)
Line 19 and 61 remove that "long" you will be redeclaring your function. You dont need line 19 by the way.

You could have returned the value you obtained from your factorial function, do it line 16. You said that double count and double y;// is the number of steps allowed well double is a floating point type you know you can't have 0.5 trials I would advice you use int or size types .
Last edited on
Topic archived. No new replies allowed.