Homework problem

Trying to get this to run and it keeps stating I haven't initialized variables r and n. I'm just starting out, but I'm completely brain fried and any tips would be appreciated.

#include <iostream>
#include <cmath>

using namespace std;

int main() /* Problem number ten from page 200 from 4th Edition A First Book of C++*/
{
int count;
double a, r, n, total;
count = 0, total = 0;
cout << "\nThis program calculates the total sum of a geometric series.";

while (count <= n)

{
cout << "\nPlease enter the variables for the term, common ratio, and the number of terms for your series: ";
cin >> a, r, n;
total = total +(a *pow(r,n));
count++;
}

cout << "The total is " << total << endl; // this totals the sum of the variables

system ("Pause");

return 0;
}
closed account (NUj6URfi)
Try cin >> a >> r >> n;
You're using variables that are not initialized, so set them to a predetermined value before-hand.

double a, r=0, n=0, total;

Instead of

double a, r, n, total;
Thanks. Looking through the tutorials and such. This is a great resource!
Topic archived. No new replies allowed.