0

Hello. Thanks in advance for helping a newbie. I am supposed to add a bottom loop (which I assume is a do while) that asks the user if he/she wishes to compute another series and as long as the answer is 'Y' or 'y' to iterate the loop until 'n' or 'N' is chosen. The loop works fine, but for some reason the answers I am supposed to get do not compute correctly. I am supposed to be getting less than 1 for every answer and after the first loop the number goes to 1.9 something. What am I doing wrong?

```
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int term, denom, finalDenom;
double sum = 0.0;
char ag;
cout << "Randy Levine \n";
cout << endl;
do
{
cout << "What is the final term?";
cin >> term;
while (term < 2 || term > 10)
{
cout << "Invalid input. Please enter a number between 2 and 10.";
cout << endl;
cout << "What is the final term?";
cin >> term;
}
finalDenom = static_cast<int>(pow (2.0, term));
for (denom = 2; denom <= finalDenom; denom *= 2)
sum = sum + (1.0 / denom);
cout << "---------";
cout << endl;
cout << sum;
cout << endl;
cout << endl;
cout << "Would you like to run another series? (Y/N): ";
cin >> ag;
if (ag == 'N' || ag == 'n')
break;
} while (ag == 'Y' || ag == 'y');
system ("pause");
return 0;
}
```