Please Find out the logical error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nkalambe
    New Member
    • Jul 2013
    • 1

    Please Find out the logical error

    Code:
    #include<iostream.h>
    #include<conio.h>
    class factorial
    {
    int no,fact;
    public:
    void getdata();
    void calculate();
    void display();
    };
    void factorial::getdata()
    {
    cout<<"Enter a no"<<endl;
    cin>>no;
    }
    void factorial::calculate()
    {
    int fact=1;
    for(int i=1;i<=no;i++)
    {
    fact=fact*i;
    }}
    void factorial::display()
    {
    cout<<"Factorial of entered number is "<<fact;
    }
    void main()
    {
    clrscr();
    factorial f;
    f.getdata();
    f.calculate();
    f.display();
    getch();
    }
    Last edited by Rabbit; Jul 20 '13, 05:37 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You have two variables named fact. The local one overrides the class one.

    Comment

    Working...