🔒 Closed C++ Class get factorial

Status
Not open for further replies.

Welcome Guest

Established
C++:
#include <iostream>
using namespace std;


class Factorial
{
    public:
        Factorial();
        void setNum(int); // setter function that will set the value of the member variable to the value passed to the class
        int getNum(); //gets/access the content of the member variable
        int solveFactorial();

    private:
        int num;
};

Factorial::Factorial()
{
    num=0;
}
void Factorial::setNum(int n)
{
    num=n;
}
int Factorial::getNum()
{
    return num;
}
int Factorial::solveFactorial()
{
    int prod=1;
    for (int i=1; i<=num; i++)
    {
        prod=prod*i;
    }

    return prod;
}
int main()
{
    int n;

    cout << "Enter a number: ";
    cin >> n;

    Factorial f;
    f.solveFactorial();

}

Mga boss, bat ayaw po lumabas ng output or result tuwing e run ko siya? Example input is 5, supposedly dapat 120 ang result. Ang lumalabas sakin ay blank or null.
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 319
    Views
  • 3
    Participants
Last reply from:
PHC-Cathy

Online now

Members online
520
Guests online
1,273
Total visitors
1,793

Forum statistics

Threads
2,277,853
Posts
28,979,277
Members
1,229,112
Latest member
rosearugay
Back
Top