Name: C++ Noob 2010-09-23 23:58
Ok so I am learning C++ and I suck.
Trying to add 1/1 + 1/2 + ... + 1/99 + 1/100
The problem is I can't get the denominator to increase as I attempt to add them.
Anyone care to point out my most likely obvious mistake?
This is what I have
#include <iostream>
using namespace std;
void main ()
{
const long MaxNum (100);
double i;
double Sum;
double x;
for (x = 1, i = 1/1, Sum = 0; x <= MaxNum; x++)
Sum += i;
cout << "Sum is " << Sum << endl;
}
Trying to add 1/1 + 1/2 + ... + 1/99 + 1/100
The problem is I can't get the denominator to increase as I attempt to add them.
Anyone care to point out my most likely obvious mistake?
This is what I have
#include <iostream>
using namespace std;
void main ()
{
const long MaxNum (100);
double i;
double Sum;
double x;
for (x = 1, i = 1/1, Sum = 0; x <= MaxNum; x++)
Sum += i;
cout << "Sum is " << Sum << endl;
}