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;
}

Recommended Answers

All 3 Replies

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;
}

Thank you so much! I see I am bracket challenged!!!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.