The result I keep getting is -2.51642e+007, and if I reverse the order of subtraction I get the reverse. My problem is that I have no clue what number that is as the shorthand notation used perplexes me. I moved the decimal place 7 spaces right for both positive and negative results and that is not correct.
Anyone know what I am doing wrong?
// SquaresandSums.cpp : Defines the entry point for the console application.
// Finds the difference between the sum of the squares of numbers 1 - 100, and the squared sum of numbers 1 - 100
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
double count = 0; //Holds the iterations count
double sum = 0; //Holds the sum of the iterations
double sqsum = 0; //Holds the square of each sum added together
double temp = 0; //For the purpose of squaring each iteration of count
double total = 0; //Holds the difference between the sum of squares and the squared sum
while(count < 100) //Execute 100 loops
{
count++; //Increase count by one each time the loop iterates
cout << count << "\n";
sum = sum + count;
cout << sum << "\n";
temp = pow(count, 2);
cout << temp << "\n";
sqsum = sqsum + temp;
if( count == 100)
{
sum = pow(sum, 2);
total = sqsum - sum;
cout << "The resulting difference is..." << total;
cout << "Exit now? (y/n)";
cin >> temp;
}
}
return 0;
}


Sign In
Create Account


Back to top









