I got error

This is a discussion on I got error within the C++ Programming forums, part of the General Programming Boards category; I got an error in my code.. can some one help me.. Code: ------ Build started: Project: Joost2, Configuration: Debug ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    6

    I got error

    I got an error in my code.. can some one help me..

    Code:
    ------ Build started: Project: Joost2, Configuration: Debug Win32 ------
    Compiling...
    Item1.cpp
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(25) : error C2601: 'GetRand' : local function definitions are illegal
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(11): this line contains a '{' which has not yet been matched
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(32) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    Build log was saved at "file://c:\Documents and Settings\Joost van Doorn\Mijn documenten\Visual Studio 2005\Projects\Joost2\Joost2\Debug\BuildLog.htm"
    Joost2 - 1 error(s), 1 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Code:
    // job3.cpp : main project file.
    
    #include <iostream> 
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <ctime>
    
    using namespace std;
    int GetRand(int min, int max);
    int main()
    {
    
    int i, r;
     {
      for (i = 0; i < 1; i++)
      {
        r = GetRand(5, 12);
        
      }
      
      return(0);
    }
    
    int GetRand(int min, int max)
    {
      static int Init = 0;
      int rc;
      
      if (Init == 0)
      {
       
        srand(time(0));
        Init = 1;
      }
    
      
      rc = (rand() % (max - min + 1) + min);
      return (rc);
    }
       char yourname [40] ;
      cout << "(Made By Job and Joost) \n";
      cout << "What is your name Sir? \n";
      cout << "Sir "; cin >>   yourname;
      cout << "Hello Sir " << yourname << "! \n";
      cout << "Welcome to the great lands of Aradona. You can navigate in the area by typing: \n";
      cout << "1 : Search for a place to train. \n";
      cout << "2 : Go to the armoury. \n";
      cout << "3 : \n";
      cout << "__________________________ \n";
      cout << "Go to: " << " ";
      int action;
      {cin >> action;
      cout << "__________________________ \n";}
      
       if(action==1) 
       {
       cout << "Wich way do you want to go?\n";
       cout <<"1 : Karadoune \n";
       cout <<"2 : Yaramana  \n";
       cout <<"3 : Rotjesland \n";
       cout <<"____________________________\n";
       cout <<"Go to: " << " ";
       cin >> action;
       cout << "__________________________\n";
       }
       
       if(action==1)
       {
       int lvl;
       lvl = 05;
       cout << "You are walking in the desert, suddenly a desertspider attacks you!\n Defend yourself, Engarde!"; 
       cout <<"The level of the desert spider is 0";
       printf ("Your number is %d\n", r);
       cout <<"___________________________ \n";
       cout <<"What will you do?          |\n";
       cout <<"1 : Attack (75 % cos)      |\n";
       cout <<"2 : Run    (35 % cos)	   |\n";
       cout <<"___________________________|\n\n";
       }
       
    if(action==2)
    	{
    	cout <<"You are walking in the green grass of the land of Aradona,\nAnd you are walking towards Yaramana,\nLuckily nobody can see you and you survive the trip.\n"; 
       cout <<"___________________________\n";
    	}
    	if(action==3)
    	{
    	cout <<"You are walking in Rotjesland, and you find a rotje\n";
    	cout <<"You light it and it explodes...\n";
    	cout <<"You have died...";
    	} 
    	
    	else
       {
       cout << "Error\n";
       cout << "__________________________ \n";
       }
      
      
        
        return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,720
    You might want to re-read line 14 and ask yourself why you wrote what you wrote.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    6
    when i remove that i get this:

    Code:
    ------ Build started: Project: Joost2, Configuration: Debug Win32 ------
    Compiling...
    Item1.cpp
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(31) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(41) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(41) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(41) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(42) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(42) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(42) : error C2143: syntax error : missing ';' before '>>'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(43) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(43) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(43) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(44) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(44) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(45) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(45) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(46) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(46) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(47) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(47) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(48) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(48) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(48) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(49) : error C2143: syntax error : missing ';' before '<<'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(49) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(49) : error C2086: 'int cout' : redefinition
            c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(40) : see declaration of 'cout'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(51) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(54) : error C2059: syntax error : 'if'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(55) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(55) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(66) : error C2059: syntax error : 'if'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(67) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(67) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(80) : error C2059: syntax error : 'if'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(81) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(81) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(85) : error C2059: syntax error : 'if'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(86) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(86) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(92) : error C2059: syntax error : 'else'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(93) : error C2143: syntax error : missing ';' before '{'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(93) : error C2447: '{' : missing function header (old-style formal list?)
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(100) : error C2059: syntax error : 'return'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(101) : error C2059: syntax error : '}'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(101) : error C2143: syntax error : missing ';' before '}'
    c:\documents and settings\joost van doorn\mijn documenten\visual studio 2005\projects\joost2\joost2\item1.cpp(101) : error C2059: syntax error : '}'
    Build log was saved at "file://c:\Documents and Settings\Joost van Doorn\Mijn documenten\Visual Studio 2005\Projects\Joost2\Joost2\Debug\BuildLog.htm"
    Joost2 - 51 error(s), 1 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    yeah and when you remove that i and r will be undeclared identifiers

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    You should move this code up into your main():
    Code:
       char yourname [40] ;
      cout << "(Made By Job and Joost) \n";
      cout << "What is your name Sir? \n";
      cout << "Sir "; cin >>   yourname;
      cout << "Hello Sir " << yourname << "! \n";
      cout << "Welcome to the great lands of Aradona. You can navigate in the area by typing: \n";
      cout << "1 : Search for a place to train. \n";
      cout << "2 : Go to the armoury. \n";
      cout << "3 : \n";
      cout << "__________________________ \n";
      cout << "Go to: " << " ";
      int action;
      {cin >> action;
      cout << "__________________________ \n";}
      
       if(action==1) 
       {
       cout << "Wich way do you want to go?\n";
       cout <<"1 : Karadoune \n";
       cout <<"2 : Yaramana  \n";
       cout <<"3 : Rotjesland \n";
       cout <<"____________________________\n";
       cout <<"Go to: " << " ";
       cin >> action;
       cout << "__________________________\n";
       }
       
       if(action==1)
       {
       int lvl;
       lvl = 05;
       cout << "You are walking in the desert, suddenly a desertspider attacks you!\n Defend yourself, Engarde!"; 
       cout <<"The level of the desert spider is 0";
       printf ("Your number is %d\n", r);
       cout <<"___________________________ \n";
       cout <<"What will you do?          |\n";
       cout <<"1 : Attack (75 % cos)      |\n";
       cout <<"2 : Run    (35 % cos)	   |\n";
       cout <<"___________________________|\n\n";
       }
       
    if(action==2)
    	{
    	cout <<"You are walking in the green grass of the land of Aradona,\nAnd you are walking towards Yaramana,\nLuckily nobody can see you and you survive the trip.\n"; 
       cout <<"___________________________\n";
    	}
    	if(action==3)
    	{
    	cout <<"You are walking in Rotjesland, and you find a rotje\n";
    	cout <<"You light it and it explodes...\n";
    	cout <<"You have died...";
    	} 
    	
    	else
       {
       cout << "Error\n";
       cout << "__________________________ \n";
       }
    Or make it into a function, and call it from main.

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    but the error about GetRand stays...
    what can we do about that?

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    oh sorry, no it works now but there is still a problem because now the generator of random numbers doesn't work any more
    Code:
    // job3.cpp : main project file.
    
    #include "stdafx.h"
    #include <iostream> 
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <ctime>
    
    using namespace std;
    int GetRand(int min, int max);
    int i, r;
    int main()
    { 
    	
      for (i = 0; i < 1; i++)
      {
        r = GetRand(5, 12);
        
      }
      
      return(0);
    }
    
    int GetRand(int min, int max)
    {
      static int Init = 0;
      int rc;
      
      if (Init == 0)
      {
       
        srand(time(0));
        Init = 1;
      }
    
      
      rc = (rand() % (max - min + 1) + min);
    	
    	
    	
    	char yourname [40] ;
      cout << "(Made By Job and Joost) \n";
      cout << "What is your name Sir? \n";
      cout << "Sir "; cin >>   yourname;
      cout << "Hello Sir " << yourname << "! \n";
      cout << "Welcome to the great lands of Aradona. You can navigate in the area by typing: \n";
      cout << "1 : Search for a place to train. \n";
      cout << "2 : Go to the armoury. \n";
      cout << "3 : \n";
      cout << "__________________________ \n";
      cout << "Go to: " << " ";
      int action;
      {cin >> action;
      cout << "__________________________ \n";}
      
       if(action==1) 
       {
       cout << "Wich way do you want to go?\n";
       cout <<"1 : Karadoune \n";
       cout <<"2 : Yaramana  \n";
       cout <<"3 : Rotjesland \n";
       cout <<"____________________________\n";
       cout <<"Go to: " << " ";
       cin >> action;
       cout << "__________________________\n";
       }
       
       if(action==1)
       {
       int lvl;
       lvl = 05;
       cout << "You are walking in the desert, suddenly a desertspider attacks you!\n Defend yourself, Engarde!"; 
       cout <<"The level of the desert spider is 0";
       printf ("%d\n", r);
       cout <<"___________________________ \n";
       cout <<"What will you do?          |\n";
       cout <<"1 : Attack (75 % cos)      |\n";
       cout <<"2 : Run    (35 % cos)	   |\n";
       cout <<"___________________________|\n\n";
       }
       
    if(action==2)
    	{
    	cout <<"You are walking in the green grass of the land of Aradona,\nAnd you are walking towards Yaramana,\nLuckily nobody can see you and you survive the trip.\n"; 
       cout <<"___________________________\n";
    	}
    	if(action==3)
    	{
    	cout <<"You are walking in Rotjesland, and you find a rotje\n";
    	cout <<"You light it and it explodes...\n";
    	cout <<"You have died...";
    	} 
    	
    	else
       {
       cout << "Error\n";
       cout << "__________________________ \n";
       }
    
    
      
      return (rc);
    }
    It's now that there is:
    The level of the desertspider is 00.. that is possible but it's always 00
    help please

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    > random numbers doesn't work any more
    rc = (rand() % (max - min + 1) + min);
    ...
    return (rc);

    1. You don't use it at all
    2. You ignore the return result anyway.

    3. if(action==1)
    You have TWO of these.

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    1 I need it to just get a random level for the desert spider
    2 I don't know where the problem is that i ignore the result (help me with it)
    3 I know that, im working on it

    Please help me

  10. #10
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    int lvl;
    lvl = 05;

    How about
    lvl = rc;
    cout <<"The level of the desert spider is " << lvl << endl;

    Even better, put most of the functionality into another function, and make getrand() return just a random value.

  11. #11
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    It works great now, Thank you very much!
    I'm still a newb in this so...

  12. #12
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    How can i get rc change per attack?
    Code:
    if(action==1)
       {
       rc = (rand() % (20 - 5 + 1) + 5);
       int lvl;
       lvl = rc;
       cout <<"You attack the desertspider!\n";
       cout <<"___________________________\n";
       cout <<"You hit the spider for " <<lvl <<endl;
       int levl;
       levl = rc;
       rc = (rand() % (4 - 0 + 1) + 0);
       cout <<"The spider hits you for " <<levl <<endl;
       }
    this doesnt work because the attack stays the same for you and for the spider

    Help please!

  13. #13
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    Try moving the second rand up a line.
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  14. #14
    Registered User
    Join Date
    Jan 2006
    Posts
    21
    Yeah i already did that and it worked... sorry about asking a too simple question
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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