Vacuus Interface Demo Errors

This is a discussion on Vacuus Interface Demo Errors within the Game Programming forums, part of the General Programming Boards category; Although I hate to admit it, I'm reasonably new to c++ - I often have little to no idea what ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    41

    Vacuus Interface Demo Errors

    Although I hate to admit it, I'm reasonably new to c++ - I often have little to no idea what each error means, which is why I'm asking for help.
    So, I recently obtained a copy of Visual Studio 2002, and have been trying to complie a small game with it.

    However, whenever I try to compile, I get the following:
    Code:
    ------ Rebuild All started: Project: Vacuus - IFD, Configuration: Debug Win32 ------
    
    Deleting intermediate files and output files for project 'Vacuus - IFD', configuration 'Debug|Win32'.
    Compiling...
    stdafx.cpp
    Compiling...
    Vacuus - IFD.cpp
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(7) : error C2065: 'string' : undeclared identifier
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(7) : error C2146: syntax error : missing ')' before identifier 'msg'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(7) : error C2059: syntax error : ')'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(19) : error C2501: 'time' : missing storage-class or type specifiers
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(19) : error C2440: 'initializing' : cannot convert from 'time_t *__w64 ' to 'int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(21) : error C2501: 'srand' : missing storage-class or type specifiers
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(21) : error C2365: 'srand' : redefinition; previous definition was a 'function'
            c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(305) : see declaration of 'srand'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(25) : error C2146: syntax error : missing ')' before identifier 'msg'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(25) : error C2086: 'int prompt' : redefinition
            c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(7) : see declaration of 'prompt'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(25) : error C2059: syntax error : ')'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(26) : error C2143: syntax error : missing ';' before '{'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(26) : error C2447: '{' : missing function header (old-style formal list?)
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(46) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(47) : error C2065: 'cin' : undeclared identifier
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(47) : error C2228: left of '.get' must have class/struct/union type
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(51) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(52) : error C2296: '>>' : illegal, left operand has type ''unknown-type''
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(54) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(54) : error C2296: '>>' : illegal, left operand has type ''unknown-type''
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(56) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(57) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(58) : error C2064: term does not evaluate to a function
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(59) : error C2296: '>>' : illegal, left operand has type ''unknown-type''
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(67) : error C2065: 'cout' : undeclared identifier
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(67) : error C2296: '<<' : illegal, left operand has type ''unknown-type''
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(67) : error C2297: '<<' : illegal, right operand has type 'char [29]'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(69) : error C2296: '<<' : illegal, left operand has type ''unknown-type''
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(69) : error C2297: '<<' : illegal, right operand has type 'char [31]'
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(70) : error C2296: '>>' : illegal, left operand has type ''unknown-type''
    So, beacuse of by newness to C++, I can't seem to fix these errors - source code:

    Code:
    // Vacuus - IFD.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    
    //Declarations
    int prompt(string msg); //This function not only returns the message provided, but also displays the interface
                            //in the full version, their should be different "types" so that the message is displayed in different areas
    int sRand(int HIGH, int LOW); //Set Random function, used to set any integer to a randomly generated value, called like: num=sRand("69","7");
                                  //In this version, this fuinction is called every time the player moves
    int begin_g(); //Used to begin the game, displays a welcome message before entering a while loop
    int pLx; //Player Location on the X plane, in the full version, like all other player vars. this var should be placed into a player class
    int pLy; //see above.
    int pHealth; //players health, doesn't change
    int input; //input variable, each pushed button should be stored in this
    
    time_t seconds; //For random stuff.
    
    time(&seconds);
    
    srand((unsigned int) seconds);
    
    //end declarations\\
    
    int prompt(string msg)
    {
        cout<<"\tPLAYER\t\tLOCATION\n";
        cout<<"\tTester\t\tX :: "<<pLx<<"\n";
        cout<<"\t"<<pHealth<<"\t\tY :: "<<pLy<<"\n";
        cout<<"\n--------------------------------------------------------------------------------\n\n";
        cout<<"\t[m] Move\t[e] Exit\n";
        cout<<"\t[h] Help\n";
        cout<<"\n--------------------------------------------------------------------------------\n\n";
        cout<<msg<<"\n>";
        return 0;
    }
    
    int sRand(int HIGH,int LOW)
    {
    return rand() % (HIGH - LOW + 1) + LOW;
    }
    
    int begin_g()
    {
         int check;//Used in conjunction with the "sRand" function
         prompt("Welcome to the Vacuus Interface demo!\nThis demo serves to show you the interface in the upcoming space simulator, Vacuus.\nHowever, the demo also allows you, the player, to move throughout the universe,\n though its functionality is limited.\nIf you require any assitance, please type H into the console to display further information.\n\n SYS: Press <RETURN> to continue:");
         cin.get();
         
         while(input != 'e')
         {
                          prompt();
                          cin>>input;
                          
                          if(input=='h') {prompt("This demo displays you the interface of an upcoming game.\n At the top of the screen, you will see some information on your player, including health, name & location.\n Below that, you will see a list of avaliable commands, each surrounded by '['s, and ']'s. Type a command to get any given effect.\nFinaly, you will see the message box, and command prompt.\n");cin>>input;}
                          if(input=='m') {pLx++; check=sRand(3,1); 
                                         if(check==1){prompt();}
                                         if(check==2){prompt("You've discovered another ship!");}
                                         if(check==3){prompt("You've discovered a planet!");}
                                         cin>>input;
                                         }
                          }
         return 0;
         }
         
    int main()
    {
        cout<<"\t\tVacuus - Interface Demo 01";
        
        cout<<"\n\t\t[1] New game.\n\t\t[2] Exit.\n>";
        cin>>input;
        
        if(input!=1)
        {
                    return 0;
                    }
        begin_g();    
        return 0;
    }
    Any ideas?
    Also, I was wondering if it is possible to open a file , whichs path would be contained in a variable - you see, I think I need to do that to make it moddable.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    from the first line
    Code:
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(7) : error C2065: 'string' : undeclared identifier
    you should include the 'string' header before use string variables

    niara

  3. #3
    Yah. Morgul's Avatar
    Join Date
    Feb 2005
    Posts
    109
    string needs to be capitalized: String

    Plus you need to include the time and iostream headers.

    Code:
    #include <ctime>
    #include <iostream>
    using namespace std;
    Sic vis pacum para bellum. If you want peace, prepare for war.

  4. #4
    Registered User
    Join Date
    May 2005
    Posts
    41
    Thanks for your help, however, now VC++ is returning errors about srand.

    I fiddled with the code a little, as VC++ didn't like RoD's way of generating random numbers.

    Code:
    //Declarations
    int prompt(string msg); //This function not only returns the message provided, but also displays the interface
                            //in the full version, their should be different "types" so that the message is displayed in different areas
    int rRand(int HIGH, int LOW); //Set Random function, used to set any integer to a randomly generated value, called like: num=rRand("69","7");
                                  //In this version, this fuinction is called every time the player moves
    int begin_g(); //Used to begin the game, displays a welcome message before entering a while loop
    int pLx; //Player Location on the X plane, in the full version, like all other player vars. this var should be placed into a player class
    int pLy; //see above.
    int pHealth; //players health, doesn't change
    int input; //input variable, each pushed button should be stored in this
    
    //time_t /*time(seconds);*/seconds; //For random stuff.
    
    //time(&seconds);
    
    srand((unsigned)time(0));
    //I haven't included the rest of the code here to save space, let me know if you need it.
    Errors:
    Code:
    Compiling...
    Vacuus - IFD.cpp
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(27) : error C2501: 'srand' : missing storage-class or type specifiers
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(27) : error C2365: 'srand' : redefinition; previous definition was a 'function'
            c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(305) : see declaration of 'srand'
    Noe, I dont understand why VC++ thinks there is another definition of srand, I did accidently call my Random function that before, which of now renamed. I've searched through the source file multiple times, and I'm yet to discover the other "definition".

    Again, thanks for your help.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    This is a bad idea:
    Code:
    int sRand(int HIGH, int LOW);
    Since there is a srand() function already in <stdlib.h> it is a very BAD idea to rename that function by simply capitalizing one letter.
    You've also changed the whole concept of srand() and so your code is quite confusing to those who understand what the real srand() does.

    srand
    Sets a random starting point.

    void srand( unsigned int seed );

    Routine Required Header Compatibility
    srand <stdlib.h> ANSI, Win 95, Win NT


    For additional compatibility information, see Compatibility in the Introduction.

    Libraries

    LIBC.LIB Single thread static library, retail version
    LIBCMT.LIB Multithread static library, retail version
    MSVCRT.LIB Import library for MSVCRT.DLL, retail version


    Return Value

    None

    Parameter

    seed

    Seed for random-number generation

    Remarks

    The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.

    Example

    /* RAND.C: This program seeds the random-number generator
    * with the time, then displays 10 random integers.
    */

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

    void main( void )
    {
    int i;

    /* Seed the random-number generator with current time so that
    * the numbers will be different every time we run.
    */
    srand( (unsigned)time( NULL ) );

    /* Display 10 numbers. */
    for( i = 0; i < 10;i++ )
    printf( " %6d\n", rand() );
    }


    Output

    6929
    8026
    21987
    30734
    20587
    6699
    22034
    25051
    7988
    10104


    Floating-Point Support Routine

    See Also rand

    Code:
    int begin_g(); //Used to begin the game, displays a welcome
    You don't have to do this but try function names like:
    Code:
    int BeginGame();
    It's far less 'vaccuous' that way.

    Code:
    int pLx; 
    int pLy; 
    int pHealth;
    This is bad for one reason. There is a coding style out there called Hungarian notation and it is a standard by which a variable's data type can be identified by looking at it's name. I don't follow it completely and a lot of Microsoft code looks like a mess because of this practice they adopted, but it has it's uses.
    Regardless if you use it or not, sticking a lower case p in front of a variable in Hungarian notation denotes the variable is a pointer.
    Someone who reads your code may mistake these variables for pointers later on in the code listing. Bad idea.

    Code:
    int pLx; //Player Location on the X plane, in the full version, like all other player vars. this var should be placed into a player class
    int pLy; //see above.
    int pHealth; //players health, doesn't change
    Try this instead so your variables are not just sitting out there floating around with no connection to each other:

    Code:
    struct Player
    {
      int iXPos;
      int iYPos;
      int iHealth;
    };
    Last edited by VirtualAce; 01-01-2006 at 05:56 PM.

  6. #6
    Registered User
    Join Date
    May 2005
    Posts
    41
    Quote Originally Posted by Bubba
    This is a bad idea:
    Code:
    int sRand(int HIGH, int LOW);
    Since there is a srand() function already in <stdlib.h> it is a very BAD idea to rename that function by simply capitalizing one letter.
    Thats the thing you see, I've renamed the function "sRand" to "rRand", but for whatever reason, VC++ still returns the error.

    Code:
    int begin_g(); //Used to begin the game, displays a welcome
    You don't have to do this but try function names like:
    Code:
    int BeginGame();
    It's far less 'vaccuous' that way.
    Will do, thanks.


    Try this instead so your variables are not just sitting out there floating around with no connection to each other:

    Code:
    struct Player
    {
      int iXPos;
      int iYPos;
      int iHealth;
    };
    Originaly, I was goint to do just that - but didn't think it would be nessescary for a "quick & simple" version - though, I suppose it can't hurt,

    Again, thanks for your help!

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Move away from using sRand or rRand. What do those do? Can you tell what they do just by looking at them? Can you tell they return a random value between LOW and HIGH? No.

    Try something like this:

    Code:
    float GetRandomFloat();
    float GetRandomFloatInRange();
    float GetRandomFloatEx()
    
    int GetRandomInteger();
    int GetRandomIntegerInRange()
    int GetRandomIntegerEx()
    Much more obvious as to what they do.

  8. #8
    Registered User
    Join Date
    May 2005
    Posts
    41
    So, yet again. I've renamed the function - but, I still get the same errors:
    Code:
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(27) : error C2501: 'srand' : missing storage-class or type specifiers
    c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Vacuus - IFD.cpp(27) : error C2365: 'srand' : redefinition; previous definition was a 'function'
            c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\stdlib.h(305) : see declaration of 'srand'
    stdafx.cpp
    
    Build log was saved at "file://c:\Documents and Settings\def\My Documents\Visual Studio Projects\Vacuus - IFD\Debug\BuildLog.htm"
    Vacuus - IFD - 2 error(s), 0 warning(s)
    I've tried the same code in Dev-C++, which returns the following:
    Code:
    25 C:\C++\Vacuus\Demo\main.cpp expected constructor, destructor, or type conversion before '(' token 
    25 C:\C++\Vacuus\Demo\main.cpp expected `,' or `;' before '(' token
    On line 25:
    Code:
    srand((unsigned int)time( NULL ));
    I'm absolutley lost to as what is going on here - one complier confuses the code with an older version, the other doesn't understand it?
    An out--dated header?

    But, again, thanks for all your help.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    I think that you have missed some '(', ';' (etc... that appears on the compilation results) but not on line 25 because
    Code:
    srand((unsigned int)time( NULL ));
    compiles right. the error sholud be before that code; try to delete that line 25 and compile again. I have had errors like that (the compiler points to a line that is right) and always was because I missed a ';' on la line over the error line, or a '(' on a large phrase where I use lots of '('.
    niara

  10. #10
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    From your original code, you seem to be calling srand from nowhere. Every function you call, must be called from main or from a subsequent function. You cannot just place a function call anywhere. Put it into main and it will probably work.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP with DX9 Errors!!!
    By Tommaso in forum Game Programming
    Replies: 7
    Last Post: 06-28-2006, 02:51 PM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 08:00 AM
  3. Results for the Encryption Contest -- June 23, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 07-07-2002, 08:04 AM
  4. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 09:14 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21