loop question

I'm told that there are two issues with this code:

1) Braces are not lined up with loop statement correctly.

2) Loop body is not indented correctly.

I'm not understanding. Any help would be appreciated. Thanks!

#include<iostream>
using namespace std;
int main()
{

int hello = 0;
while( hello < 5)
{

hello++;
cout<<"HELLO!"<<endl;

}
cout << endl;
system ("PAUSE");
}
This is how I would do it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
using namespace std;

int main()
{
    int hello = 0;
    while( hello < 5)
    {
        hello++;
        cout<<"HELLO!"<<endl;
    }
    cout << endl;
    system ("PAUSE");
}
Thoose are just style problems and not anything that actually affects anything other than your ability to read the code.
not anything that actually affects anything other than your ability to read the code.
Debugging/maintaining well indented code is easier

2) Loop body is not indented correctly.
6
7
8
9
    int hello = 0;
    while( hello < 5)
    {
        hello++;
Can be done with a for loop: http://www.cplusplus.com/doc/tutorial/control/#for
Topic archived. No new replies allowed.