unable to exit loop

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
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    cout << "This program sums multiple series of numbers.\n"
    << "Terminate eash sequence by entering a negative number.\n"
    << "Terminate the series by entering two nrgative numbers in a row\n\n";

    int accumulator;
    for(;;)
    {
        accumulator =0;
        cout << "Start the next sequence\n";

        for(;;)
        {
            int nValue = 0;
            cout << "Enter next number: ";
            cin >> nValue;

            if(nValue = 0)
            {
                break;
            }
            accumulator += nValue;
        }
        if(accumulator == 0)
        {
            break;
        }
        cout << "The total for this sequence is "
        << accumulator
        << endl << endl;
    }
    cout << "Thank you" << endl;


    return 0;
}

the program runs but i am unable to exit the first loop
if(nValue = 0)
you probably want <= operator there. if you want to exit when negative.

your first loop wont exit because accumulator is never 0.
thanks
Topic archived. No new replies allowed.