My program works fine, but I am struggling developing a user-defined function for the for loop. Everything I try won't work, any help would be greatly appreciated.
using namespace std;
double firstTerm = ' ';
double commRatio = ' ';
double total, numTerms = ' ';
cout << "Program will compute terms in a Geometric Series"<<endl<<endl;
cout << "Enter the first term in the series: ";
cin >> firstTerm;
cout<<"Enter the common ratio for the series: ";
cin >> commRatio;
cout<<"Enter the number of terms to use: ";
//while (numTerms < 2)
cout << fixed << showpoint;
cout <<setprecision(4)<< "Terms in series for Common Ration
of "<<commRatio<<" are:"<<endl;
cout << setprecision(9);
for (int counter = 1; counter <= numTerms; counter++ )
sum = firstTerm * pow(commRatio,(counter-1));
total += sum;
cout << setw(20) <<sum<< endl;
Not sure why the pow function is used.
In a geometric series, each term can be derived from the previous one by a simple multiplication by the common ratio.
A question: are you trying to list all of the terms, or just calculate the sum of all the terms?
Okay I got rid of the ' '; and initialized to 0;
I am trying to list the terms.
My delema is now this, any value returned from the function to main is 0, how do I take the input value from the function to main?
double startTerm (double firstTerm, string str1);
double startTerm (double ft, string str1)
cout<<"Enter first term: ";
while (newTerm > 1)
if (newTerm <= 0)
cout<< str1 << " " <<endl;