Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Learning to program in visual c++ 2008 express

Options
  • 22-03-2009 4:08pm
    #1
    Registered Users Posts: 2,315 ✭✭✭


    This is the code i've been trying to get to work in visual c++ 2008 express edition. Could someone please tell me where I went wrong. Could be miles off as only learning it a day or two now.

    #include <iostream>
    using namespace std;

    int main ()
    {
    cout << "Comment 1" << endl;
    cout << "Comment 2" << endl;

    for (int i = 0; i < 10; i++)

    <<
    cout << i;
    >>



    system("pause");
    }


Comments

  • Closed Accounts Posts: 1,567 ✭✭✭Martyr


    [PHP]for (int i = 0; i < 10; i++)

    <<
    cout << i;
    >>[/PHP]

    the problem is there.


  • Registered Users Posts: 2,315 ✭✭✭deceit


    Thanks, I tried this and it seems to work:

    #include <iostream>
    using namespace std;

    int main ()
    {
    cout << "Comment 1" << endl;
    cout << "Comment 2" << endl;

    for (int i = 0; i < 10; i++)

    cout << i << endl;

    system("pause");
    }


  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    for your for loops you really should use {} for the statements you want to loop

    for eg.
    for(int i = 0 ; i < 10 ; i++)
    {
        cout << i << endl;
    }
    

    the following will work but if you need two or more statements done in a loop you need { }
    for(int i = 0 ; i < 10 ; i++)
        cout << i << endl;
    


  • Registered Users Posts: 2,315 ✭✭✭deceit


    for your for loops you really should use {} for the statements you want to loop

    for eg.
    for(int i = 0 ; i < 10 ; i++)
    {
        cout << i << endl;
    }
    

    the following will work but if you need two or more statements done in a loop you need { }
    for(int i = 0 ; i < 10 ; i++)
        cout << i << endl;
    

    Thanks, thats alot of help :).


  • Closed Accounts Posts: 2,219 ✭✭✭Lab_Mouse


    You will also find at the start a few of your problems will stem from typo's either forgetting semi colons or curly brackets.Some times these throw up strange error reports(not nessarily 'your missing a ';'!)

    compile your code regularily(even every couple of lines of code at the start till your confident of your syntax) because i found if i didnt i could end up with nearly 30 errors,which i found daunting to go back and fix.

    and enjoy the coding!


  • Advertisement
  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    also to add what lab_mouse said, compilers often single out a line of code where the error is e.g.: Error on line 43.

    always check the line above as it possible that an error on line 42 may be causing the error.


Advertisement