Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# An easy question for the more experienced than I

Posted on 1998-10-05
Medium Priority
155 Views
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
Question by:truancy
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 1

Expert Comment

ID: 1174452
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

LVL 1

Expert Comment

ID: 1174453
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

LVL 1

Accepted Solution

Booth882 earned 40 total points
ID: 1174454
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 Comment

ID: 1174455
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

LVL 1

Expert Comment

ID: 1174456
howd it go truancy?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
###### Suggested Courses
Course of the Month8 days, 8 hours left to enroll