0

hello i have my code here and i want to add two numbers together constantly

#include <iostream>

using namespace std;

int main()
{

int a = 10;
int b = 10;


cout << a+b;

return 0;
}


how to make A+B add constantly?

Edited by dakerao: n/a

4
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by Chilton
0

If you just want to keep outputting a+b you could use an infinite loop. something along the lines of

while(true)
{
    // code here
}

I have to ask why you want to do this?

0

oh no i need to keep adding a and b so like a+b = 20 and then add a and b again and it would be 40 but do that in a continuation i guess thats a loop but exactly how would i do that?

Edited by dakerao: n/a

0

So in your example a and b are both 10. You add them together and you get 20. Now you want to set a and b to 20 and do it again?

0

you have to reassign a and b to equal eachother in intervals while in a loop

like

while(a+b!=40)
{
a=a+b;
b=a;
}
0

So in your example a and b are both 10. You add them together and you get 20. Now you want to set a and b to 20 and do it again?

I think it's more on the line of adding the result of a + b to a + b, continually in a loop.

To the OP, you could have a third variable, sum, initialized to zero and do something like:

sum = sum + a + b;

In this case though, a and b wouldn't change.

Question, do you want a and b to change?

Edited by Chilton: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.