Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Learning to program in visual c++ 2008 express

  • 22-03-2009 04:08PM
    #1
    Registered Users, Registered Users 2 Posts: 2,327 ✭✭✭


    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, Registered Users 2 Posts: 2,327 ✭✭✭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, Registered Users 2 Posts: 26,449 ✭✭✭✭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, Registered Users 2 Posts: 2,327 ✭✭✭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, Registered Users 2 Posts: 26,449 ✭✭✭✭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