I can not stop my loops

In the code below I can never actually stop the program by entering a blank space as it is supposed to. Does anyone know why?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//sqauredemo
//demonstrates the use of a function which processes args

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

//square - returns the square of its argument.
//doubleVar - the value to be squared
// returns - square of doubleVar
double square(double doubleVar)
{
    return doubleVar * doubleVar;
}
//displayExplanation - prompt user as to the rules of the game.
void displayExplanation(void)
{
    cout << "This program sums the square of multiple\n"
        << "series of numbers.\n"
        << "Terminate each sequence by entering a negative number.\n"
        << "Terminate the series by entering a blank space.\n";
    cout << endl;
    return;
}

//sumSquareSequence - accumulate the square of the number entered into a sequence until the user enters a negative
//number.
double sumSqareSequence(void)
{
    double accumulator = 0.0;
    for(;;)
    {
        double dValue = 0;
        cout << "Enter next number: ";
        cin >> dValue;

        if(dValue < 0)
        {
            //exit the loop
            break;
        }
        double value = square(dValue);
        //now add the square to the accumulator
        accumulator += value;
    }
    //return the accumulated value
    return accumulator;
}

int main(int nNumberofArgs, char* pszArgs[])
{
    displayExplanation();
    //continue to accumulate numbers..
    for(;;)
        {
        cout << "Enter next sequence";
        cout << endl;
        double accumulatedValue = sumSqareSequence();

        //terminate if the sequence is zero or negative
        if (accumulatedValue <= 0)
            {
                break;
            }
        //now output the accumulated result.
        cout << "\nThe total of the values squared is: ";
        cout << accumulatedValue;
        cout << endl;
        cout << endl;
        }
}
Topic archived. No new replies allowed.