Solved

An easy question for the more experienced than I

Posted on 1998-10-05
5
149 Views
Last Modified: 2010-04-01
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
Comment
Question by:truancy
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Grailman
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

by:Grailman
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

by:
Booth882 earned 10 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

by:truancy
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

by:Booth882
ID: 1174456
howd it go truancy?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 78
Building cUrl in Windows v7.43.0 4 28
why "." vs "->" 23 119
Using Delphi code in a Builder project that uses a DLL 3 107
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now