Here is the assignmnent I need to complete:
"Write a program to calculate and print the result of the following two operations:
1/1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/99999999 + 1/100000000
and
1/100000000 + 1/99999999 + 1/99999998 + 1/99999997 + ... + 1/3 + 1/2 + 1/1
Results should be totaled and printed once using float variables for each calculation and once using double variables for each calculation. There should be a total of four answers printed. Make sure that the answers are adequately labeled. You may use any of the three loop mechanisms (while, do-while, or for)."
I've gotten the part of the program using the "double" variables to execute, but whenever I slip in the "float" variables part of the program, the window is blank when I try to run it. I know a float variable can only hold 7 digits, but I'm not sure how to resolve this. I appreciate any tips.
#include <iostream>
using namespace std;
void main ()
{
float f;
float fsum;
double i;
double Sum;
for (f = 1, fsum = 0; f <= 100000000; f++)
fsum = fsum + (1/f);
cout << "The sum of all numbers 1/1 through 1/100000000 is " << fsum << endl;
for (f = 100000000, fsum = 0; f >= 1; f--)
fsum = fsum + (1/f);
cout << "The sum of all numbers 1/100000000 through 1/1 is " << fsum << endl;
for (i = 1, Sum = 0; i <= 100000000; i++)
Sum = Sum + (1/i);
cout << "The sum of all numbers 1/1 through 1/100000000 is " << Sum << endl;
for (i = 100000000, Sum = 0; i >= 1; i--)
Sum = Sum + (1/i);
cout << "The sum of all numbers 1/100000000 through 1/1 is " << Sum << endl;