Can't fix it

Hi everybody,

I apparently have a problem with one of my first self-written programs:


#include <iostream>
using namespace std;

int n1;
int n2;

int main()
{
cout << "Type in starting number" << endl;
cin >> n1 >> endl;
cout << "Type in ending numer" << endl;
cin >> n2 >> endl;
{
do
{
n1=n1+1, n1++;
}

while
{
n1<=n2;
}

}
return 0;
}


My program should basicially count from the first to the second number I type in, can't figure out how to get it run.

Have a nice day,

ATEST
Errors:
-endl is not used with cin--AFAIK
-for the condition for a do...while loop, you used {} instead of ()
-also, the ';' should have come after ')' for the while part.


Corrected code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int n1;
int n2;

int main()
{
    cout << "Type in starting number" << endl;
    cin >> n1 ;
    cout << "Type in ending numer" << endl;
    cin >> n2 ;
    {
        do
        {
            n1=n1+1, n1++;
        }while(n1<=n2);
    }
    return 0;
}
1
2
3
do {
    ... //code
} while( ... ); //condition 


http://cplusplus.com/doc/tutorial/control
Thank you very much!!! But it still doesn't work how it's supposed to do, if I type in "1" as the starting number and e.g. "7" as the ending number i want it to count like:
1
2
3
4
5
6
7

Have a nice day,

ATEST
@OP:
if I type in "1" as the starting number and e.g. "7" as the ending number i want it to count like

As in displaying it, then cout in the loop with starting number+1, while it is less than ending number.

Hope it HELPS!!!
Works perfectly now, just like it should , again, Thanks!!!
Topic archived. No new replies allowed.