Statments, And Loops (C++)

Im not sure how to use the if statment. or same goes with any statment or loop correctly in C++, I seem to be doing it wrong, yet i looked at other source code and it seems i have done it right.

My Way:

#include <iostream>

using namespace std;

int main()
{
    for (int x = 0; x < 10; x++) {
         cout<< x <<endl;
         }

Now see at after the for loop and the cout the Closing bracket for closing the for loop is supposed to line up with the f in for autmoatically it dont and when i do finsh the program it gives me an error. Im not sure whats going on and I need help with this.

www.cprogramming.com way:

#include <iostream>	

using namespace std;
		
int main()                            // Most important part of the program!
{
  int age;                            // Need a variable...
  
  cout<<"Please input your age: ";    // Asks for age
  cin>> age;                          // The input is put in age
  cin.ignore();                       // Throw away enter
  if ( age < 100 ) {                  // If the age is less than 100
     cout<<"You are pretty young!
"; // Just to show you it works...
  }
}

Now there’s Does line up perfectly and works great what can I be doing wrong