0

A loop that has a setMethod for a private variable. I want this set-method to add value in the first turn of the loop, and then just stop. How can i do that?

Code:

for(int x = 0; x > 5; x++)
{
   setnum(5);
   cout << getnum();
   setnum(getnum() -1);
}

this code should output: 1 2 3 4 5

but when doing it it outputs: 5 5 5 5 5
The setnum(5) is resetting.

How to prevent it? with setnum(5) inside the loop.

Navnath Godse
  • 2,233
  • 2
  • 23
  • 32
Nathaniel
  • 5
  • 2

1 Answers1

0

Insted of > than put x < 5 and pass x as a parameter to setnum() method.

for(int x = 0; x < 5; x++)
{
  setnum(x);

}
Priscilla Jobin
  • 609
  • 7
  • 19