I've been writing a program that calculates the natural logarithm of 2 for the user. It prompts for the number of terms to calculate, and how many steps in between each value to display. I can't figure out how to only display certain values. Ex: If the user inputs 10 terms to compute and for the values to be displayed every 2 steps. Any help is appreciated.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const string PROGDESCRIPTION = "Program will approximate the natural logarithm of 2 ";
double UserPrompt(string prompt)
{
double terms;
Please use code tags to make it easier to read your code and point out line numbers.
First off, there is a problem with your UserPrompt function. Your while loop isn't doing anything the way it is written, and you can enter a negative number when you are asked to retry and it will go through just fine.
It should be written as:
1 2 3 4 5 6
while(terms < 1) {
cout << "ERROR - Input must be positive and non-zero! Please Try again. " << endl;
cout << prompt;
cin >> terms;
}
return terms;
To get to your posted question:
To print after so many iterations, you can just keep a counter.
I'm having trouble getting the right output, tried both methods and it's still outputting five values each times the number of terms. For example I'm trying to get it so if the user inputs 6 terms with 2 steps each, it will only display the values every 2 steps, and display something like this: