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 get that this line of code must deal with the total of a character (a digit in this case) add to a sum.
Obv. you would have to create either a float or have int figures, right?
total would be a float
at the beginning of this for loop you have n = 1 and add it to total which should be zero to start.
1/1=1,so you are adding one to total
next it would be----- total(or 1) = total +1/2, so now total = 1.5
and this keeps going, adding 1/3,1/4,1/5,ect.., till n is bigger than 100,000,000
while (first_num <= 1000000)
{
sum = sum + 1/first_num;
first_num++;
}
cout << "1. The sum of the numbers: " << sum << endl;
sum2 = 0;
second_num = 1;
while (second_num <= 1000000)
{
sum2 = sum2 + 1/second_num;
second_num++;
}
cout << "2. The sum of the numbers: " << sum2 << endl;
sum3 = 0;
third_num = 1000000;
/* There is an error below... can you see it? */
while (third_num <= 1)
{
sum3 = sum3 - 1/third_num;
third_num--;
}
cout << "3. The sum of the numbers: " << sum3 << endl;
sum4 = 0;
fourth_num = 1000000;
/* There is an error below... can you see it? */
while (fourth_num <= 1)
{
sum4 = sum4 - 1/fourth_num;
fourth_num--;
}
cout << "4. The sum of the numbers: " << sum4 << endl;
}
Here's the problem:
Can't put 100,000,000 without the program halting when I run it (1,000,000 works).
Why is that?
Also wondering why the three last sums are different from the first when I do put 1,000,000.
Final question , how can i take it another step and put into one loop?
Will I need to break and cont ?