Hi all,

Class assignment is to list all numbers between user input.

I have this much, but have no idea how to get it to list the numbers between them. I know this is simple, but it still eludes me ;)

Thanks in advance!

#include <iostream>
using namespace std;

int main ()

int  x, y;
cout << "Please key in a start number: "; cout <<endl;
cin >> x;
cout << endl;
cout << "Please key in an end number: "; cout << endl;
cin >> y;
while (x < y)
      x = x + 1;
cout << x;
        cout << endl << endl;
        system ("PAUSE");
        return 0;
9 Years
Discussion Span
Last Post by Narue

When starting out, it helps to always use braces for compound statements. Your loop should look like this:

while ( x < y ) {
  x = x + 1;
  cout<< x <<'\n';

If you don't have the braces, only the first statement will be the whole of the loop body. So in your code, the loop is translated like this:

while ( x < y ) {
  x = x + 1;

Just pretend they're required and you can't go wrong. It's surprisingly difficult to casually, accidentally forget to type both, and if you get only one, you're practically guaranteed a syntax error.

This question has already been answered. 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.