### Yes or No Loop

I've coded a program to calculate the Riemann zeta function of a number. This is a school assignment and it requires me to implement a 'yes or no' loop so that the user can input another number without exiting the program. I got the inner loop to work and the calculations match with Wolfram Alpha's one. But when I put a loop to repeat the program, all the computations remain the same e.g. if I enter 3, I get 1.202. If I enter 1.5, I still get the same answer.

 ``1234567891011121314151617181920212223242526272829303132`` ``````#include #include const double Max = 1e-7; using namespace std; int main() { int inx = 1; double n, zeta = 1, sum; char repeat = 'Y'; while (repeat == 'y' || repeat == 'Y') { cout << "Input a number to compute it's Riemann's zeta function: "; cin >> n; while (zeta > Max) { zeta = (1/(pow(inx,n))); inx++; sum = sum + zeta; } cout << "The Riemann zeta function is: "; cout << sum << endl; cout << "Do you want to continue? (y/n) "; cin >> repeat; } cout << "The end." << endl; return 0; } ``````
You're not resetting the values of zeta and num for each new calculation. At the start of the second calculation, they are still set to the values they had at the end of the first one, and so on.
Okay. How would I go about resetting the values? I declared zeta = 1 above the while loop and tried setting num = 0.
The point is, each time you do a new calculation - because the user types "Y" - you need to reset them at the start. Can you see where in your program you start doing each new calculation? (Hint: What have you changed in your program to make it do more than 1 calculation?)
yes, MikeyBoy's answer is a correct view:
sum = 0;
inx = 1;
zeta = 1;
Recall that the Riemann zeta function is one on the complex numbers; you'll want to create a complex number struct

 ``12345`` ``````struct Complex { double Real; double Imaginary; };``````

That is, assuming your instructor didn't specify to define it over the reals.
Thank you everyone, I got it.
Topic archived. No new replies allowed.