Compiler errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keith katthy
    New Member
    • Oct 2007
    • 24

    #1

    Compiler errors

    Dear all,

    Why this program, cannot compile?

    Compiling...
    90.cpp
    C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 2) : error C2871: 'std' : does not exist or is not a namespace
    C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 8) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    90.exe - 2 error(s), 0 warning(s)
    [code=cpp]
    #include <iostream.h>
    using namespace std;

    const int COL = 3;
    const int ROW = 3;

    int main(int argc, char *argv[]);
    {
    int i;
    int time;
    int srand,NULL,rand ;
    int matrix[COL][ROW] = {0}; // declare and initialize a 2d array

    // seed the random number generator
    // with the current time
    srand( (unsigned)time( NULL ) );

    // loop through the 2d array
    // assigning a random number
    for (int i = 0; i < COL; i++)
    {
    for (int j = 0; j < ROW; j++)
    {
    matrix[i][j] = rand();
    }
    }

    // print the matrix
    for (int i = 0; i < COL; i++)
    {
    for (int j = 0; j < ROW; j++)
    {
    printf("%d\t", matrix[i][j]);
    }
    printf("\n");
    }
    return 0;
    }[/code]
    Last edited by sicarie; Oct 5 '07, 12:51 PM. Reason: Code tags
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    The program can't compile because there are syntax errors.

    #include <iostream.h> : Deprecated. Use <iostream> instead. If you don't understand why, then whatever resource you used to learn C++ is outdated. Get C++ Primer by Lippman, Accelerated C++ by Koenig, or another recognized and well recommended book.

    Of course, you never use anything within iostream. Interestingly, this looks like an attempt at taking some C code and patching it as C++. Because you use srand (without the appropriate header). The same goes for printf, which is in cstdio in C++. But why use printf if you include <iostream>.

    You have aroused my suspicions, so I think you'll want to explain what is going on here.

    Comment

    • keith katthy
      New Member
      • Oct 2007
      • 24

      #3
      I have done acoretion, but still have error...anybody can tell me to correct its.?
      :\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 20) : error C2064: term does not evaluate to a function
      C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 20) : error C2064: term does not evaluate to a function
      C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 21) : error C2064: term does not evaluate to a function
      C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 25) : error C2086: 'i' : redefinition
      C:\Documents and Settings\Admini strator\Desktop \MASTER\90.cpp( 34) : error C2086: 'i' : redefinition
      Error executing cl.exe.

      90.exe - 5 error(s), 0 warning(s)

      #include <stdio.h>
      #include <stdlib.h>
      #include <time.h>

      int main ()
      {

      const int COL = 3;
      const int ROW = 3;

      int main(int argc, char *argv[]);
      {
      int i;
      int time;
      int srand;
      int matrix[COL][ROW] = {0}; // declare and initialize a 2d array

      // seed the random number generator
      // with the current time
      srand( (unsigned)time( NULL ) );
      srand ( 1 );

      // loop through the 2d array
      // assigning a random number
      for (int i = 0; i < COL; i++)
      {
      for (int j = 0; j < ROW; j++)
      {
      matrix[i][j] = rand();
      }
      }

      // print the matrix
      for (int i = 0; i < COL; i++)
      {
      for (int j = 0; j < ROW; j++)
      {
      printf("%d\t", matrix[i][j]);
      }
      printf("\n");
      }
      return 0;
      }
      }

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by keith katthy
        [code=c]
        int main ()
        {

        const int COL = 3;
        const int ROW = 3;

        int main(int argc, char *argv[]);
        {
        int i;
        // etc.
        [/code]
        What are you trying to accomplish here?

        kind regards,

        Jos

        Comment

        Working...