
Need Help
I have to write code for class that sums numbers up to a certain point like 5 billion using an increment that we put in using cin, so if we start at 0 and go to 5 billion by increments of 2 it would be like 0+2=2 2+2=4 and so on. When i cout my sums they always read zero can anyone help
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
/* Declared Integers*/
double dsum, dx, da, i, ep, ci, pl;
/*Assign Variables*/
cout << "What is your starting point using a decimal"<< endl;
cin >> dx;
cout << "What is your ending point using a decimal"<< endl;
cin >> ep;
cout << "What is your counting increment using a decimal"<< endl;
cin >> ci;
cout << "How many times should a sum be printed" << endl;
cin >> pl;
dsum = 0.0;
da = 1.0;
/* Prints Columns */
cout << "Line" << "\t" << "Every "<< pl<< "th" << "\t" << "Sum" << "\n" << endl;
/*Sums the Numbers*/
while (da<=pl)
{
i = 1.0;
while (i <= ep/pl)
{
dsum = dsum + dx;
i++;
dx+ci;
}
/* prints out the numbers*/
cout << setprecision(20)<< da << "\t" << (ep/pl)*da << "\t" << dsum << "\n" << endl;
da++;
}
system ("pause");
return 0;
}

(Like 5 billion or is it 5 billion)?????????

Ignoring everything else, this is why your dsum will always be zero, if your dx is zero.
Quote:
Originally Posted by
Kess0990
Code:
while (i <= ep/pl)
{
dsum = dsum + dx;
i++;
dx+ci; // Result of this expression is not assign to anything.
}