sorry i'm newbie in here....i have a problem in C++..and this is the first time i did the programming codes, so that is so confusing for me...anyone can help me to solved this problem?

The value e^x can be approximated by the sum
1 + x + x2/2! + x3/3! + … + x^n/n!
Write a program that takes a value x as input and outputs this sum for n taken
to be each of the values 1 to 100. The program should also output ex
calculated using the predefined function exp. The function exp is a predefined
function such that exp(x) returns an approximation to the value ex. The
function exp is in the library with the header file cmath. Your program should
repeat the calculation for new values of x until the user says she or he is
through.
Use variable of type double to store the factorials or you are likely to produce
integer overflow (or arrange your calculation to avoid any direct calculation of
factorials). 100 lines of output might not fit comfortably on your screen. Output
the 100 output values in a format that will fit all 100 values on the screen. For
example, you might output 10 lines with 10 values on each line.

thx.

Welcome to the DaniWeb! You should know it's discouraged to do homework for you. However, demonstrate your efforts and many people will help guide you by offering corrections, comments, etc.

For any project it's important to understand the problem. So, for example do you know what the sympbols ^ and ! mean in this setting. In other words if I ask you to calculate a^b for any value a and b do you know how to do that? Do you know what a! means. In these exercises, as in many programs, loops will will probably be used extensively. Are you familiar with the different types of loops and when to use them. If you can answer yes to all those questions, then start writing your program by writing out on paper what you plan to do. When writing the code start from the simplest program you can write and get it to compile and run appropriately. Then, step by step write more code and compile/run as you go. Never write your entire programs code and then try to compile/run (or at least don't do it until you can code like the experts here and it's a straightforward program at that!).

Here's how you might start the first part of the assignment:
Add 1 plus x and store in a variable called result. Then using a loop controlled by the value of n, where n ranges from 2 to 100, for each value of n calculate x^n and n!. Then divide x^n by n! and add that value to result.

sorry...
i have a problem again..:mrgreen:
how, if i want to do again when i press N..???

this my codes

#include <iostream>
using namespace std;
int main()
{
char input[200];
char response;
do{
cout << " Input the words that you want:\n";
cin.getline(input,200);
int k = 0, count = 0;
while (input[k] != '\0')
{
if (input[k]==' ')
count++;
k++;
}
cout << count+1 << " Words" << endl;
for (char i='a';i<='z';i++)
{
int j = 0, count = 0;
while (input[j] != '\0')
{
if (tolower(input[j]) == i)
count++;
j++;
}
if (count > 0)
cout << i << " = " << count << endl;
}
cout << " Do you want to exit [Y/N] ? ";
cin >> response;
}while (response=='n' || response=='N');
system("pause");
return 0;
}

thx

Edited 3 Years Ago by happygeek: fixed formatting

Your problem is that the newline character ( '\n' ) which remains in the input stream after you give the choice (yes or no) is picked up by the getline function and hence your program fails to run as expected.

Either place a getchar () after the cin >> response statement or resort to better methods of accepting input from the user.

And btw, using system ("pause") is not good choice for making the console window stop, better use getchar () again or cin.get () .

This question has already been answered. Start a new discussion instead.