You are using a version without Ads of this website. Please, consider donating:

### Summation Program.

I'm supposed to be making a program that can find the summation of a function (such as x^5+10) from x=1 to n, which is inputted by the user. I'm supposed to do this once using only "for" loops, and once using only "while" loops. But so far, I don't even know how to get that far. This is what I have, but it doesn't do anything, primarily because I have no idea how to do a summation on C++.

 ``123456789101112131415161718192021222324252627282930`` ``````#include /*included to allow for cout/cin to be used*/ #include using namespace std; int main() { int cont; int n; int sum = 0; int number; cout << "Do you want to find a summation? (Y/N) \n"; cin >> cont; int N; if (cont == N) { return 0; } cout << "Enter an n value. n= "; cin >> n; //int func = (pow(x,5)+10); return 0; }``````

Thanks for any help.
Last edited on
You just need to use a loop that runs from 1 to n (the user's input). Inside the loop, find the value of the function at that value for X (1 through n) and add it to sum. For instance, in the function you gave, it would be something like
 `` `` ``sum += pow(i, 5) + 10;``

Start with doing this in a for loop, then changing it to a while loop should be trivial.
Last edited on
Topic archived. No new replies allowed.