Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

I need help creating a C++ program that computes the factorial of an integer between 1-20 using a nested loop. Integer and respective factorial must be printed in 2 columns on the screen.

OpenStudy (anonymous):

Here's what I have so far. I don't know how to get the integers and factorials to print though :/ #include<iostream> using namespace std; int main() { int num,factorial=1; cout<<" Enter Number To Find Its Factorial: "; cin>>num; for(int k=1; k<=num; k++) { factorial=factorial*k; } cout << "Interger" << " " << "Factorial" << endl; cout << num << " " << factorial << endl; system ("PAUSE"); return 0;

OpenStudy (hba):

Can you please show me the output you are getting on console?

OpenStudy (anonymous):

Integer Factorial 4 24 But according to the assignment it should also be showing the factorials for 1-3 as well. 17! and a few others are also coming up wrong and I have no idea how to fix those.

OpenStudy (hba):

Can i do this in java?

OpenStudy (anonymous):

Not really sure what that is other than another language. If it'll help solve the problem in C++ then I guess. It's a C++ class though.

OpenStudy (hba):

Well Java is a object oriented language too,the only difference would be the syntax.

OpenStudy (anonymous):

Oh okay. Well by all means. I'm just so frustrated with this.

OpenStudy (hba):

Don't worry it's easy :)

OpenStudy (hba):

here you go.

OpenStudy (rsmith6559):

amorable, output the column headers before your for loop and output num and factorial inside the loop.

OpenStudy (doc.brown):

Do a loop from 1 to integer. do the math output "Integer" loopNumber "Factorial" factorial close the loop

OpenStudy (doc.brown):

oh yeah, @rsmith6559 got it Output "Integer" "Factorial" Do a loop from 1 to integer. do the math output loopNumber factorial close the loop

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!