#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    What's wrong with Loop: C++


    #include <iostream>
    using namespace std;

    int main()

    {


    // for loop includes initialiation, loop four times
    unsigned int num = 0;
    unsigned int product = 1;

    for ( unsigned int count =0 ; count<=4; ++count )

    {

    num = 5 - count; // keep track of factorial constituent

    product = product * num;

    if (count = 0)
    {
    cout << num << endl; //outputs current facotrial constituent
    }


    else{
    cout << " x (5 - " << count << ")"; //output factorial formula for each count

    }






    }


    cout << "\n" << "\n" << product;


    system( "PAUSE" );

    return 0;


    } // end main


    Why is this an infinite loop? I'm trying to get it to be N * (N - 1) * (N -2) etc

    -Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0
    if ( count = 0 ) should be

    if ( count == 0)


    Originally Posted by Pharaoh Atem
    #include <iostream>
    using namespace std;

    int main()

    {


    // for loop includes initialiation, loop four times
    unsigned int num = 0;
    unsigned int product = 1;

    for ( unsigned int count =0 ; count<=4; ++count )

    {

    num = 5 - count; // keep track of factorial constituent

    product = product * num;

    if (count = 0)
    {
    cout << num << endl; //outputs current facotrial constituent
    }


    else{
    cout << " x (5 - " << count << ")"; //output factorial formula for each count

    }






    }


    cout << "\n" << "\n" << product;


    system( "PAUSE" );

    return 0;


    } // end main


    Why is this an infinite loop? I'm trying to get it to be N * (N - 1) * (N -2) etc

    -Thanks

IMN logo majestic logo threadwatch logo seochat tools logo