Sign in to follow this  
KOSH-30

why doesnt this work

Recommended Posts

this is my code question at the bottom
#include <iostream>
#include <string>
#include <fstream>
using namespace std;


	////load map

///void draw(){

//	fstream map("map.txt",ios_base::in);
//for(int i = 0; i <10;i++){
//for(int j = 0; j <10;j++){
int hero_health =70; 
int hero_strenght = 2;
void intro(void);		 

class Hero
{
	
	int enemy_healt;
	int enemy_strenght;

	bool fight;
//// void movehero();
///	void intro();
//	void menu();
//	void status();
///	void battle();
	
};
class Enemy
{

};	
int menu(void)
{
int command ;

cout <<"These are your choices numbers (1-6) n,w,e,s,battle,status"<<endl;
do 
cin >> command;

while(command <0 && command > 6 );
return command;
}

	int status()  ///check for enemy?
	{		
		cout <<"your status is "<<endl;
		cout <<endl<<"your health is" <<hero_health<<endl;
	cout <<endl<<"your strenght is " <<hero_strenght<<endl;
	return true;
	};	
	int main (void)
	{
	
		int command ;
		cout <<"i am at your command "<<endl;
while (command = menu ())
{
	switch (command)
	{

	case 1:
		cout <<"u chose case 1"<<endl;
		break;
	case 2:
		cout <<"u chose case 2 "<<endl;
		break;
	case 3:
		cout <<"u chose case 3 "<<endl;
		break;
	case 4:
		cout <<"u chose case 4 "<<endl;
		break;
	case 5:
		cout <<"u chose case 5 "<<endl;
	case 6:
		int status();
		break;
	}

	 //bool grass ground and move

}
return 0;
	
	}

void intro(void)
{



	string hero_name;
    cout <<"welcome 2 my try of a rpg." <<endl;  // 2 slashes 
    cout <<"what is your name hero?" ;
	cin >> hero_name;
	cout <<"Are you ready 2 begin the adventure " <<hero_name.c_str() <<endl;

	
};

you can compile this code it works. but my question is why it wont go 2 void intro(void) the intro txt and why wont it in case 6 go 2 int(status) i tryed all comdinations of void but wont work ,i checked my books and i should be normal code http://www.newgameprojects.net/ edit: added [source] tags -SiCrane [Edited by - SiCrane on December 5, 2004 3:39:59 AM]

Share this post


Link to post
Share on other sites
1) it doesnt enter intro() because you never call intro.

cleaned up, because im feeling generous:


#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void intro(void);

int hero_health =70;
int hero_strength = 2;



class Hero
{
int enemy_health;
int enemy_strength;

bool fight;
};

class Enemy
{

};


void intro(void)
{
string hero_name;
cout <<"welcome 2 my try of a rpg." <<endl;
cout <<"what is your name hero?" ;
cin >> hero_name;
cout <<"Are you ready 2 begin the adventure " <<hero_name.c_str() <<endl;
};

int status() ///check for enemy?
{
cout <<"your status is "<<endl;
cout <<endl<<"your health is" <<hero_health<<endl;
cout <<endl<<"your strength is " <<hero_strength<<endl;
return true;
};

int menu(void)
{
int command ;

cout <<"These are your choices numbers (1-6) ,w,e,s,battle,status"<<endl;

do
cin >> command;
while(command <0 && command > 6 );

return command;
}

int main (void)
{
intro();

int command ;
cout <<"i am at your command "<<endl;

while (command = menu ())
{
switch (command)
{

case 1:
cout <<"u chose case 1"<<endl;
break;
case 2:
cout <<"u chose case 2 "<<endl;
break;
case 3:
cout <<"u chose case 3 "<<endl;
break;
case 4:
cout <<"u chose case 4 "<<endl;
break;
case 5:
cout <<"u chose case 5 "<<endl;
case 6:
status();
break;
}
}
return 0;
}





Share this post


Link to post
Share on other sites
OK, it's a very subtle bug in your case six:


case 6:
int status();
break;


What you are actually doing here is declaring a function, I think, instead of calling it. Simple remove the int before status i.e.


case 6:
status();
break;


That should fix it.

EDIT: didn't notice xanin had actually spotted that and fixed it, oh well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this