Game Code Messed Up (Mainly struct{};)

This is a discussion on Game Code Messed Up (Mainly struct{};) within the C++ Programming forums, part of the General Programming Boards category; Here's the code: Code: #include <iostream.h> #include <string.h> int newgame(); int loadgame(); struct player_stats { char name[50]; char type[50]; int ...

  1. #1
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38

    Game Code Messed Up (Mainly struct{};)

    Here's the code:

    Code:
    #include <iostream.h>
    #include <string.h>
    int newgame();
    int loadgame();
    struct player_stats
    {
    	char name[50];
    	char type[50];
    	int health;
    	int mana;
    	int strength;
    	int magic;
    	int agility;
    	int endurance;
    	int resist_ice;
    	int resist_water;
    	int resist_fire;
    	int resist_evil;
    	int resist_holy;
    	int resist_lightning;
    	char weapon[50];
    	char armor[50];
    	char shield[50];
    	char head[50];
    	char wrist1[50];
    	char wrist2[50];
    	char neck1[50];
    	char neck2[50];
    	char belt[50];
    	char belt_acc1[50];
    	char belt_acc2[50];
    	char skill1[50];
    	char skill2[50];
    	char skill3[50];
    	char skill4[50];
    	char skill5[50];
    	char skill6[50];
    	char skill7[50];
    	char skill8[50];
    	char skill9[50];
    	char skill10[50];
    	int skill1_lvl;
    	int skill2_lvl;
    	int skill3_lvl;
    	int skill4_lvl;
    	int skill5_lvl;
    	int skill6_lvl;
    	int skill7_lvl;
    	int skill8_lvl;
    	int skill9_lvl;
    	int skill10_lvl;
    };
    int main()
    {
    	char input;
    	cout<<"Welcome to ConsoleQuest!  Please select an option:"<<endl;
    	cout<<"(N)ew Game"<<endl;
    	cout<<"(L)oad Game"<<endl;
    	cout<<"(E)xit"<<end;
    	cin>>input;
    	switch(strlwr(input))
    	{
    		case 'n': newgame();
    			break;
    		case 'l': loadgame();
    			break;
    		case 'e': return 0;
    			break;
    	}
    	return 0;
    }
    int newgame()
    {
    	player_stats player;
    	char name[50];
    	char type;
    	cout<<\n<<endl;
    	cout<<"Please choose a character name:"<<endl;
    	cin>>name;
    	player.name = name;
    	cout<<\n<<endl;
    	cout<<"Please choose a character type:"<<endl;
    	cout<<"(for help on character types type help)"<<endl;
    	cout<<\n<<endl;
    	cout<<"(H)oly Knight"<<endl;
    	cout<<"(D)ark Knight"<<endl;
    	cout<<"(I)ce Elemental"<<endl;
    	cout<<"(F)ire Elemental"<<endl;
    	cout<<"(L)ightning Elemental"<<endl;
    	cout<<"(W)ater Elemental"<<endl;
    	cout<<"H(o)ly Elemental"<<endl;
    	cout<<"(E)vil Elemental"<<endl;
    	cout<<"(M)age"<<endl;
    	cout<<"(C)leric"<<endl;
    	cout<<"(N)ecromancer"<<endl;
    	cout<<"N(a)tural Elf"<<endl;
    	cout<<"Da(r)k Elf"<<endl;
    	cin>>type;
    	switch(strlwr(type))
    	{
    	case 'h': player.type = "holy_knight";
    		break;
    	case 'd': player.type = "dark_knight";
    		break;
    	case 'i': player.type = "ice_elemental";
    		break;
    	case 'f': player.type = "fire_elemental";
    		break;
    	case 'l': player.type = "lightning_elemental";
    		break;
    	case 'w': player.type = "water_elemental";
    		break;
    	case 'o': player.type = "holy_elemental";
    		break;
    	case 'e': player.type = "evil_elemental";
    		break;
    	case 'm': player.type = "mage";
    		break;
    	case 'c': player.type = "cleric";
    		break;
    	case 'n': player.type = "necromancer";
    		break;
    	case 'a': player.type = "natural_elf";
    		break;
    	case 'r': player.type = "dark_elf";
    		break;
    	case "help": help();
    		break;
    	}
    	return 0;
    }
    Here are the errors:

    Code:
    --------------------Configuration: Source - Win32 Debug--------------------
    Compiling...
    Source.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(59) : error C2065: 'end' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(61) : error C2664: 'strlwr' : cannot convert parameter 1 from 'char' to 'char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(77) : error C2017: illegal escape sequence
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(77) : error C2065: 'n' : undeclared identifier
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(80) : error C2106: '=' : left operand must be l-value
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(81) : error C2017: illegal escape sequence
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(84) : error C2017: illegal escape sequence
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(99) : error C2664: 'strlwr' : cannot convert parameter 1 from 'char' to 'char *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(101) : error C2440: '=' : cannot convert from 'char [12]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(103) : error C2440: '=' : cannot convert from 'char [12]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(105) : error C2440: '=' : cannot convert from 'char [14]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(107) : error C2440: '=' : cannot convert from 'char [15]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(109) : error C2440: '=' : cannot convert from 'char [20]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(111) : error C2440: '=' : cannot convert from 'char [16]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(113) : error C2440: '=' : cannot convert from 'char [15]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(115) : error C2440: '=' : cannot convert from 'char [15]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(117) : error C2440: '=' : cannot convert from 'char [5]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(119) : error C2440: '=' : cannot convert from 'char [7]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(121) : error C2440: '=' : cannot convert from 'char [12]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(123) : error C2440: '=' : cannot convert from 'char [12]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(125) : error C2440: '=' : cannot convert from 'char [9]' to 'char [50]'
            There is no context in which this conversion is possible
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(127) : error C2051: case expression not constant
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(127) : error C2065: 'help' : undeclared identifier
    Error executing cl.exe.
    
    Source.exe - 23 error(s), 0 warning(s)

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    1)
    Code:
    cout<<"(E)xit"<<endl;
    2) You can NOT assign to an entire array with =
    3) You have a lot of the same type of items in the structure. Instead of having seperate variables use arrays and enums.
    4)
    Code:
    case "help"
    Cases must be a constant integer value
    5) You call help() but provide no prototype

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    dude...do you code the whole thing and then run it? I suggest writing a bit at a time and try running it then. Debug as much as possible and as frequent as plausible. Some of your errors are very elementary.... you should do things like that your self... we are not your debuggers....

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    Thankyou ALL!!! perfect help! <3 u Thantos.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    <3 u Thantos
    You're welcome but that just scares me

  6. #6
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    lol Thantos...

    more problems, fixed old problems, but got new ones (also added error detection and what-not for menus, possibly slow down processing, and could be more efficient, but it's a console for god sakes, it's just text shouldn't matter that much), so here they are:

    The code:

    Code:
    #include <iostream.h>
    #include <string.h>
    int newgame();
    int loadgame();
    int alignment();
    int help();
    int good();
    int neutral();
    int evil();
    struct player_stats
    {
    	char name[50];
    	int alignment;
    	int element;
    	int type;
    	int health;
    	int mana;
    	int strength;
    	int magic;
    	int agility;
    	int endurance;
    	int resist_ice;
    	int resist_water;
    	int resist_fire;
    	int resist_evil;
    	int resist_holy;
    	int resist_lightning;
    	int weapon;
    	int armor;
    	int shield;
    	int head;
    	int wrist1;
    	int wrist2;
    	int neck1;
    	int neck2;
    	int belt;
    	int belt_acc1;
    	int belt_acc2;
    	int skill1;
    	int skill2;
    	int skill3;
    	int skill4;
    	int skill5;
    	int skill6;
    	int skill7;
    	int skill8;
    	int skill9;
    	int skill10;
    	int skill1_lvl;
    	int skill2_lvl;
    	int skill3_lvl;
    	int skill4_lvl;
    	int skill5_lvl;
    	int skill6_lvl;
    	int skill7_lvl;
    	int skill8_lvl;
    	int skill9_lvl;
    	int skill10_lvl;
    };
    player_stats player;
    int main()
    {
    	int input;
    	cout<<"Welcome to ConsoleQuest!  Please select an option:"<<endl;
    	cout<<"1. New Game\n";
    	cout<<"2. Load Game\n";
    	cout<<"3. Exit\n\n";
    	cin>>input;
    	cout<<"\n\n";
    check_switch:
    	switch(input)
    	{
    		case 1: newgame();
    			break;
    		case 2: loadgame();
    			break;
    		case 3: return 0;
    			break;
    		default: cout<<"Error: Incorrect Input\n\n";
    			cin>>input;
    			cout<<"\n\n";
    			goto check_switch;
    	}
    	return 0;
    }
    int newgame()
    {
    	char name[50];
    	int yn;
    	cout<<"Please choose a character name:\n\n";
    	cin>>player.name;
    	cout<<"\n\n";
    	cout<<"You chose "<<player.name<<" to be your name.\nAre you sure?\n";
    	cout<<"1. Yes\n";
    	cout<<"2. No\n\n";
    	cin<<yn;
    	cout<<"\n\n";
    check_switch:
    	switch(yn)
    	{
    	case 1: alignment();
    		break;
    	case 2: newgame();
    		break;
    	default: cout<<"Error: Incorrect Input\n\n";
    		cin<<yn;
    		cout<<"\n\n";
    		goto check_switch;
    		break;
    	}
    	return 0;
    }
    int alignment()
    {
    	cout<<"Please choose a character alignment:\n\n";
    	cout<<"1. Good\n";
    	cout<<"2. Neutral\n";
    	cout<<"3. Evil\n";
    	cout<<"4. Back\n\n";
    	cin>>player.alignment;
    	cout<<"\n\n";
    check_switch:
    	switch(player.alignment)
    	{
    	case 1:	break;
    	case 2:	break;
    	case 3:	break;
    	case 4: break;
    	default: cout<<"Error: Invalid Input.\n";
    		cin>>player.alignment;
    		cout<<"\n\n";
    		goto check_switch;
    		break;
    	}
    	int Yes_No;
    	switch(player.alignment)
    	{
    	case 1:	cout<<"You chose to follow the character alignment 'Good'.\nAre you sure?\n";
    	cout<<"1. Yes\n";
    	cout<<"2. No\n\n";
    	cin>>Yes_No;
    	cout<<"\n\n";
    check_if1:
    	switch(Yes_No)
    	{
    	case 1: break;
    	case 2: break;
    	default: cout<<"Error: Incorrect Input\n\n";
    		cin>>Yes_No;
    		cout<<"\n\n";
    		goto check_if1;
    		break;
    	}
    	case 2: cout<<"You chose to follow the character alignment 'Neutral'.\nAre you sure?\n";
    	cout<<"1. Yes\n";
    	cout<<"2. No\n\n";
    	cin>>Yes_No;
    	cout<<"\n\n";
    check_if2:
    	switch(Yes_No)
    	{
    	case 1: break;
    	case 2: break;
    	default: cout<<"Error: Incorrect Input\n\n";
    		cin<<Yes_No;
    		cout<<"\n\n";
    		goto check_if2;
    		break;
    	}
    	case 3: cout<<"You chose to follow the character alignment 'Evil'.\nAre you sure?\n";
    	cout<<"1. Yes\n";
    	cout<<"2. No\n\n";
    	cin>>Yes_No;
    	cout<<"\n\n";
    check_if3:
    	switch(Yes_No)
    	{
    	case 1: break;
    	case 2: break;
    	default: cout<<"Error: Incorrect Input\n\n";
    		cin<<Yes_No;
    		cout<<"\n\n";
    		goto check_if3;
    		break;
    	}
    	if(Yes_No)
    	{
    		switch(player.alignment)
    		{
    		case 1: good();
    			break;
    		case 2: neutral();
    			break;
    		case 3: evil();
    			break;
    		}
    	}
    	else alignment();
    	return 0;
    }
    int good()
    {
    	cout<<"Please select a character type.\n\n";
    	cout<<"1. Angel\n";
    	cout<<"2. Cleric\n";
    	cout<<"3. Diety\n";
    	cout<<"4. Knight\n";
    	cout<<"5. Mage\n\n";
    	cin>>player.type;
    check_switch:
    	switch(player.type)
    	{
    	case 1: break;
    	case 2:	break;
    	case 3:	break;
    	case 4:	break;
    	case 5:	break;
    	default: cout<<"Error: Incorrect Input\n\n";
    		cin>>player.type;
    		goto check_switch;
    	}
    	return 0;
    }
    The errors:

    Code:
    --------------------Configuration: Source - Win32 Debug--------------------
    Compiling...
    Source.cpp
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(96) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(106) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(165) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(181) : error C2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(202) : error C2601: 'good' : local function definitions are illegal
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(224) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.
    
    Source.exe - 6 error(s), 0 warning(s)
    Also, how do you set Visual C++ 6.0 to show how many lines of code are in the current source file?
    Last edited by CodeNinja; 07-18-2004 at 08:35 PM.

  7. #7
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Get rid of the gotos. A simple do{}while will work just as well and will show the structure more clearly.
    For the binary '<<' errors can you highlight the lines please. I'm not going to count all the lines to find the error.

  8. #8
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    how do i do that? (when you say count you mean make the compiler list the line numbers, and if so how do i do that in Visual C++)

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    usally if you double click on the error it'll take you to that line

  10. #10
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    okay here it is, narrowed it down to one lame error...

    all the << operator errors were when i used << with cin.

    now... here it is, in the previous code...

    Code:
    int good()
    {
    	cout<<"Please select a character type.\n\n";
    is giving me the following error:

    Code:
    C:\Program Files\Microsoft Visual Studio\MyProjects\ConsoleQuest\Source.cpp(202) : error C2601: 'good' : local function definitions are illegal
    on the following line:

    Code:
    {
    of the previous code segment.

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    switch(player.alignment)
    {
    case 1:cout<<"You chose to follow the character alignment 'Good'.\nAre you sure?\n";
    cout<<"1. Yes\n";
    cout<<"2. No\n\n";
    cin>>Yes_No;
    cout<<"\n\n";
    check_if1:
    This is missing a }
    Which is causing the above error.

  12. #12
    01000011 00100000 0010000
    Join Date
    Jul 2004
    Posts
    38
    yea, I found it, thanks.

    now I just have to figure out why my code just continuosly loops between "choose your alignment" and "are you sure?". Like you choose your alignment, and then say you are sure, and it asks for you to choose your alignment again... :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting from C to C++
    By Taka in forum C++ Programming
    Replies: 5
    Last Post: 04-08-2009, 02:16 AM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-21-2006, 11:23 PM
  3. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-25-2006, 11:14 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. game code
    By The WaRped OnE in forum Game Programming
    Replies: 1
    Last Post: 02-28-2002, 07:46 PM

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