DevC++ homework and im not familiar with it

dukemnukem67

Prominent
Dec 5, 2017
2
0
510
Im big noob about this, can somebody say if this is typing number in while loop correct, if not can you correct it? (never got teached about DevC++ soo i don't Know a thing).
As a school homework that we never did.The question was that We have to type numbers from 1 to 5 using while loop.


#include <iostream>
using namespace std;

int main () {
int a = 1;
do {
cout<< a << endl;
a = a + 1;
} while( a < 6 );

return 0;
}
 
Solution
Should work, some edits:

#include <iostream>
using namespace std;

int main () {
int a = 1;
do {
cout<< a << endl;
a++;
} while( a < 6 );

return 0;
}

King_V

Illustrious
Ambassador
The assignment specifically says to use a while loop, so I imagine OP isn't allowed to use a for loop for this assignment.

EDIT: though I'm not sure if that means explicitly to use this type of while loop:
while
{
// functionality here
}

Or if the do-while is permitted.
 

rgd1101

Don't
Moderator


What happen when you run it?