Adding the sum of the previous value, and continuing from there.

I'm trying to write a code where it should add on from the current information. For example, let's say A is 11 for the first and second calculation. B should be 11 for the first calculation, and 22 for the second. Here's the rest of my code.

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
#include <iostream>
#include <string>

using namespace std;

int main()
{
    char datax, datay, dataA, dataB;
    string Type;
    int x=10;
    int y=1;
    int A=x+y;
    int B;
    string type;
    int num;
    int total;

    cout << "x\t" << "y\t" << "A=x+y\t" << "B=sum of A\t" << "Type" << endl;
    cout << "=============================================" << endl;
    while (x <= 10 && x > 0)
    {
        if (B %2!=0)
         {
             type = "ODD";
         }
            else if (B %2==0)
         {
             type = "EVEN";
         }
         cout << x << "\t" << y << "\t" << A << "\t" << B << "\t" << type << endl;
         x--;
         y++;
         for (B = 0; A = 11;)
         {
             cout << B;
         }
    }
    return 0;
}
B += A; //equivalent to B = B+A


1
2
3
4
         for (B = 0; A = 11;)
         {
             cout << B;
         }
¿what are you trying to do there?
I tried looking around and trying different things but it wouldn't work. And I finally got it! Just had to define B=11, and then B+=A! Thanks!
Topic archived. No new replies allowed.