-1
#include <iostream>
using namespace std;

int main () {

int n = 100;

while (n > 50) {

cout << n << ", ";
--n;

}

cout << "DONE!";

system("PAUSE");

}

Basically, this program will put the integer in a while loop and keep on subtracting one until it reaches 50, but I want it to do the opposite. Instead of --n (which keeps on subtraction one from the value), I want it to add one.

Okay, so how would you do this with multiplication? Because **n isn't working...?

DerekDev
  • 63
  • 1
  • 9
  • 5
    This may surprise you, but that'd be `++n`. – Luchian Grigore May 29 '15 at 15:37
  • Genuinely laughing aloud at the above comment, Derek it might be worth having a quick google before doing a SO post, save some time :) – Aphire May 29 '15 at 15:40
  • Doing `++n` as other's said will increment the value. But you will also need to change your condition in `while` or else just doing `++n` will go to an infinite loop. Change `n > 50` to `n < x` where `x` is the last number that you want. – Prerak Sola May 29 '15 at 15:43
  • 1
    This is far too basic and won't be a useful addition to this Q&A repository. You can find it very early on in your C++ book, which I encourage you to begin reading now. – Lightness Races in Orbit May 29 '15 at 15:55

1 Answers1

1
int n = 0;

while (n < 50) {
   cout << n << ", ";
   n++;
}
Maresh
  • 4,644
  • 25
  • 30