### computing the Riemann zeta function

I am new to c++ and taking a college coarse on it. Immediately i need help on one of my labs. I'm suppose to provide an inner loop that computes the zeta function and the other loop is just press y for to continue, anything else exit.so far i got this:

 ``12345678910111213141516171819202122232425262728293031323334353637383940`` ``````#include #include #include using namespace std; int main() { double x, n,zeta; char flag = 'y'; while(flag=='y') { cout <<"Enter x value "; cin >> x; n=1; zeta=0 while(1/(pow(n,x))>1e-7) { zeta= 1/(pow(n,x)); zeta=+zeta; n++; } cout<<"Sum is "<>flag; } system("pause"); return 0; }``````

I can't seem to get the formula right.
Last edited on
When learning, it is extremely important to use correct indenting. It may seem trivial and something you can 'fix' later, but when your programs get to be more than 40 lines, it will become impossible to read.

But I think this is what you are looking for:

 ``12345678910111213141516`` ``````#include double zeta(double s) { const double precision = 1e-7; double output = 0.0; double calculation = 1.0; for (int denom = 2; abs(output - calculation) > precision; ++denom) { output += calculation; calculation = 1.0 / pow(denom, s); } return output; }``````

If you haven't learned functions yet, then just stick lines 5-13 inside of your while(flag=='y') loop. If you can't figure out where your while loops start and end, then fix your formatting.
Last edited on
i forgot to mention i must put it in a "while" loop, and my prof. has restricted the class from using break (except in switch) and constant?. Is it also possible to dumb things down to a level of a beginner, i don't want to use anything beside what i learn which is simple stuff what i just kind of did.
Topic archived. No new replies allowed.