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?
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?
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?
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?
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?
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;
}
ahh ha thanks for that Imgreg :)
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?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.