Challenging homework help!

Hey all, I have two homework assignments left to do until I am done with my semester and on X-mas break, but these two are nearly impossible for me. I honestly don't even know where to start on them. I am terrible at programming, but managed to figure out my previous assignments using many tutorial videos as well as my book. These two are the only ones that stand in my way now >:(


1) Write a program that asks the user to enter an integer, then calculates and prints the factorial of the number.

2) Write a program to calculate ex using the formula:
ex = 1 + x/1! + x2/2! + x3/3! + .......
Allow the user to enter the integer number x , then do the calculation in a loop (for or while), taking it out ten iterations.
For example, if the user entered 2 , the program would calculate: e2 = 1 + 2/1! + 22/2! + 23/3! + .......




Any help is much appreciated. Thanks! =)
you should start with the parts you can do, i think cout and cin shouldn't be a problem.

the math part for the first task:if you have no idea, look it up at wikipedia or anywhere else
for the 2nd task, you need to find a pattern in that formula so you can simply use it in a loop.
There are some nice websites which can help you out with what you are looking for. Maybe you can try them out and get help from professional tutors in the subject , rather than posting it online.
http://www.assignmentstore.com
Talvira wrote:
1) Write a program that asks the user to enter an integer, then calculates and prints the factorial of the number.

This one is pretty easy. I'm sure you know how to read in an int and store it in a variable. The only part that's left is creating a factorial function. Factorial is based around recursion (or, if you really want to, for loops) and returns the evaluated expression, typically as an int.

To help you get started, my Factorial function prototype is int Factorial(int n);

You should start at n = 1, then move up to n = 2, n =3, n = 4, etc. If by the time you get to 10 you don't see the pattern or don't understand how to use recursion (my function only consists of 4 lines I believe), you should probably read up on recursion again.

Talvira wrote:
2) Write a program to calculate ex using the formula:
ex = 1 + x/1! + x2/2! + x3/3! + .......
Allow the user to enter the integer number x , then do the calculation in a loop (for or while), taking it out ten iterations.
For example, if the user entered 2 , the program would calculate: e2 = 1 + 2/1! + 22/2! + 23/3! + .......


Once you have the factorial function from 1, this one will be much easier. The equation, if I understand it correctly, is pretty easy to implement. You should just make a function called e that returns a double. Possible prototype double e(int x);. Your teacher says 10 iterations, so that would more than likely be a for loop, and at least one call to factorial in each loop.

Good luck.
Topic archived. No new replies allowed.