Hi.
I'm trying to create a program to compute the Riemann zeta function

which is defined as 1+(1/(2^x))+(1/(3^x))+(1/(4^x))+....

for user input of x

and will keep adding as long as the term is less than (1e-7).

but I keep getting 1.79301e-307 for every number I put

#pragma hdrstop
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
#define limit 1e-7
cout<<"This program will compute the Riemann zeta function for real values of x>1."<<endl<<endl;
double number, sum, term;
char answer;
cout<<"Enter a value for x. ";
cin>>number;
cout<<"Do you want to continue?";
cin>>answer;
while(term > limit)
{
    sum=0;
    term=0;
    int denominator=1;
    term=(1/(pow(denominator,number)));
    sum=sum+term;
    denominator++;



}

cout<<sum;

}

help please!

I might be completely wrong about this but cout isn't my problem at all. The problem is that I'm not getting the output I'm expecting.

while(term > limit)

At this point, the first time this line of code is reached, what is the value of term?

Also, look at this section of code:

int denominator=1;
term=(1/(pow(denominator,number)));

What value will demoninator have in that calculation, every time?

Edited 3 Years Ago by Moschops

dear you are doing an error in line 20.
Declare and initialize denominator before the loop start not with in the loop.
beacause every time it will assin value 1, and you are getting same result.
only edit it and fix it.

Thanks you moschop. I defined term before the loop and fixed a couple of things and it worked!

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