Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
October 11th, 2013, 12:23 AM
 Pharaoh Atem
Registered User

Join Date: Oct 2013
Posts: 1
Time spent in forums: 3 m 23 sec
Reputation 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
October 11th, 2013, 12:38 AM
 TheShellWave
Registered User

Join Date: Oct 2013
Posts: 9
Time spent in forums: 4 h 18 m 38 sec
Reputation Power: 0
if ( count = 0 ) should be

if ( count == 0)

Quote:
 Originally Posted by Pharaoh Atem #include 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

 Viewing: Dev Shed Forums > Programming Languages > C Programming > What's wrong with Loop: C++