[Webinar] Streamline your web hosting managementRegister Today

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 157

# An easy question for the more experienced than I

We are dealing with for loops in class and we have to write a program to find the factorial of 1-10, I had the factorial part right by simply doing this
for(x=1;x>=10;x--)
{
product=product*x
cout>>product<<'\n
}
But I cant get it to say the factorial of 2 is " the factorial of 3 is ", those have to be incorporated in another for loop somehow. Can anyone please help.
0
truancy
• 2
• 2
1 Solution

Commented:
Slight problem w/ the loop:

set x equal to 1
as long as x is greater than or equal to 10 (it ain't so!)
decrease x by 1 on each pass through the loop

Can't work that way. Also I'll assume the missing ';' after the two lines inside the loop are typos as is the '>>' which should be '<<'.   ;-)

0

Commented:
Slight problem w/ the loop:

set x equal to 1
as long as x is greater than or equal to 10 (it ain't so!)
decrease x by 1 on each pass through the loop

Can't work that way. Also I'll assume the missing ';' after the two lines inside the loop are typos as is the '>>' which should be '<<'.   ;-)

0

Commented:
you dont need a new loop, just add to your output line in the loop you already have, like

cout << "the factorial of " << x << " is " << product << '\n';

because x is the value and product is the factorial.
0

Author Commented:
Actually the semicolons are what we use in Borlands Turbo C++, I dunno about anything else.....and ya they are typos, I was in a hurry I know which way they go =), anyway thanks for the help, I will try the proposed answer tomorrow in class.
0

Commented:
howd it go truancy?
0

## Featured Post

• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.