program error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayman723
    New Member
    • Sep 2006
    • 40

    program error

    hello all;

    I was running this simplep program and get an error . can anyone tell me whats wrong with it

    code

    # include < iostream >
    using std::cout
    int main()
    {

    for ( int x=1; x<= 10; x++ )
    {
    if ( x>5)
    break;
    cout << x <<" ";
    }



    error message

    syntax error : 'int' should be preceded by ';'

    thanks
  • koder
    New Member
    • Sep 2006
    • 23

    #2
    hi,
    i given a semicolon and it compiled..i am not sure of syntax of c++
    see the code below

    #
    Code:
     include <iostream>
    using std::cout;
    
     main()
    {
    
    for ( int x=1; x<= 10; x++ )
    { 
    if ( x>5)
    break;
    cout << x <<" ";
    return 0;
    
    }
    }
    and the out put is 1
    let me know it is correct or not..plzzz

    Comment

    • ayman723
      New Member
      • Sep 2006
      • 40

      #3
      thanks a million, it worked.

      :)

      Comment

      • D_C
        Contributor
        • Jun 2006
        • 293

        #4
        Code:
        using std::cout
        int main()
        should have a semicolon, like
        Code:
        using std::cout[b];[/b]
        int main()
        Also, you need an extra } at the end. Also, please keep it int main, otherwise in invokes undefined behavior.

        Comment

        Working...