Another Problem with my program (DUMB ME)

I am having yet another problem with my code.

Page 1 of 1

7 Replies - 1051 Views - Last Post: 07 August 2007 - 08:54 PM Rate Topic: -----

#1 ilandra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 03-August 07

Another Problem with my program (DUMB ME)

Post icon  Posted 06 August 2007 - 11:09 PM

I don't know why my code is terminating before taking the input from the user. Could someone please help?

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <dos.h>
#include <mem.h>
#include <conio.h>
#include <ctime>
#include <windows.h>
#include <string>
using namespace std;
char PlayerName [20];
char PlayerInput;
char Human;
char Elf;
char Ogre;
char Dwarf;
char Warrior;
char Rogue;
char Mage;
char Cleric;
char Class;
char Race;
char Score;
char Choice;
string PlayerStrength;
string PlayerIntelligence;
string PlayerWisdom;
string PlayerConstitution;
string PlayerDexterity;
string ClassName;
string RaceName;
long int PlayerHP;
long int PlayerMana;
long int PlayerMovement;
long int Kill;
int main()
{
	system("color 0B");
	cout<<"Welcome to the RPG game that I am trying to create."<<endl;
	cout<<"I hope that you are ready to play the game.		"<<endl;
	cout<<"___________________________________________________"<<endl;
	cout<<"|												 |"<<endl;
	cout<<"|		 1) Create New Character				 |"<<endl; /* Player Decides to create a character */
	cout<<"|		 2) Exit								 |"<<endl; /* Player doesn't want to play */
	cout<<"|_________________________________________________|"<<endl;
	cin>>Choice;
	if (Choice == '2')
	{
			   cout<<"Alright if you are sure we are now exiting.\n\n"<<endl;
			   system("pause"); /* Game exits if 2 is chosen */
			   return 0;
}
else 
if (Choice == '1')
{
		   cout<<"Great it is time to make your character."<<endl; /* Game progresses if Player chooses 1 */
		   system("pause");
		   system("cls");
		   }
		   cout<<"Adventurer please tell me what your name is: "<<endl;
		   cin>>PlayerName;
		   
		   cout<<PlayerName<<" did I get that right? Y/N "<<endl;
		   cin>>Choice;
		   if (Choice == 'N'||Choice == 'n')		  /*Player doesn't like name or entered it wrong */
		   {
					  cout<<"Sorry for that"<<endl;
					  return 0;
					  }
					  else
					  if (Choice == 'Y'||Choice == 'y') /*Player likes name and continues */
					  {
								 cout<<PlayerName<<" ";
								  system("pause");
								 }
								 cout <<"Now we must go and find out your race and class"<<endl;
								 cout <<"_______________________________________________"<<endl;
								 cout <<"|											 |"<<endl;
								 cout <<"|	   (W)arrior							 |"<<endl; /* Player picks warrior */
								 cout <<"|	   Žogue							   |"<<endl; /* Player picks rogue */
								 cout <<"|	   (M)age								|"<<endl; /* Player picks mage */
								 cout <<"|	   Šleric							  |"<<endl; /* Player picks cleric */
								 cout <<"|_____________________________________________|"<<endl;
								 cin >> Class; /* Player enters the class */
								 
										   if (Class == 'W'||Class == 'w')
								 {
										  ClassName = "Warrior";
										  }
										  else 
										  if (Class == 'R'||Class == 'r')
										  {
												   ClassName = "Rogue";
												   }
												   else
												   if (Class == 'M'||Class == 'm')
												   {
															 ClassName = "Mage";
															 }
															 else
															 if (Class == 'C'||Class == 'c')
															 {
																	   ClassName = "Cleric";
																	   }
cout <<"Here is how you look so far: \n"<<PlayerName<<" the "<<ClassName<<endl;
system("pause");
cout << "\n\n Please pick a race from the following: "<<endl;
cout <<"______________________________________________"<<endl;
cout <<"|											|"<<endl;
cout <<"|		  (H)uman						   |"<<endl; /* Player picks human race */
cout <<"|		  (E)lf							 |"<<endl; //Player picks elf race
cout <<"|		  (O)gre							|"<<endl; // Player picks ogre race
cout <<"|		  (D)warf						   |"<<endl; // Player picks dwarf race
cout <<"|____________________________________________|"<<endl;
cin >> Race;
if ( Race == 'H'||Race == 'h')
{
	 RaceName = "Human";
	 }
	 else
	 if (Race == 'E'||Race == 'e')
	 {
			  RaceName = "Elf";
			  }
			  else
			  if (Race == 'O'||Race == 'o')
			  {
					   RaceName = "Ogre";
					   }
					   else
					   if (Race == 'D'||Race == 'd')
					   {
								RaceName = "Dwarf";
								}
system("cls");
system ("color 07");
if (Class = 'W')
{
PlayerStrength = '8'; 
PlayerDexterity = '8'; 
PlayerConstitution = '8';
PlayerWisdom = '8';
PlayerIntelligence = '8';

}
else 
if (Class = 'R')
{
PlayerStrength = '8';
PlayerDexterity = '8';
PlayerConstitution = '8';
PlayerWisdom = '8';
PlayerIntelligence = '8';
}
else 
if (Class = 'M')
{
PlayerStrength = '8';
PlayerDexterity = '8';
PlayerConstitution = '8';
PlayerWisdom = '8';
PlayerIntelligence = '8';
}
else 
if (Class = 'C')
{
PlayerStrength = '8';
PlayerDexterity = '8';
PlayerConstitution = '8';
PlayerWisdom = '8';
PlayerIntelligence = '8';
}

		  

system ("pause");

system("cls");
system("color F0");
cout <<PlayerName<<" "<<ClassName<<" "<<RaceName<<endl;
cout <<"You are standing in the middle of a room that is"<<endl;
cout <<"Very well lit. Off to one side there is a desk"<<endl;
cout <<"behind the desk sits and older woman who beckons you"<<endl;
cout <<"Goodafternoon "<<PlayerName<<" my name is Deirdre and I am the"<<endl;
cout <<"tutorial secretary. Do you need to know how to play the game?<Y/N>"<<endl;
cin >> Choice;
if (Choice == 'N' || Choice == 'n')
{
	cout << "Going straight to program not yet implimented";
	cout << "Program is exiting";
getch();
		   return 0;
}
else 
if (Choice == 'Y' || Choice == 'y')
{
system ("cls");
cout << "The first thing that we are going to do is to take a look"<<endl;
cout << "at your score. To do this type <score>"<<endl;
cin >>Score;
cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
cout <<"		  Strength: "<<PlayerStrength<<endl;
cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
cout <<"		  Constitution: "<<PlayerConstitution<<endl;

cout <<"Let us take a look at your stats first and foremost."<<endl;
cout <<"The first thing that you will notice is Strength which"<<endl;
cout <<"will determine a various list of things including how"<<endl;
cout <<"much you can carry. Higher strength can also increase"<<endl;
cout <<"damroll, resulting in higher damage to the enemy."<<endl;
cout <<" "<<endl;
cout <<"Your dexterity is especially important to rogues"<<endl; 
cout <<"nimble fingers help when stealing. But for all"<<endl;
cout <<"classes, Dex improves the character's ability to"<<endl;
cout <<" hold many items, and improves the overall AC, or armor class."<<endl;
cout <<"Intelligence is an attribute that is as important to a mage as"<<endl;
cout <<"it is to a  cleric. Higher intelligence results in more mana "<<endl;
cout <<"gained per level, and allows all classes to learn skills and "<<endl;
cout <<"spells with fewer practices."<<endl;
cout <<" "<<endl;
system ("pause");
system ("cls");
cout <<"Wisdom is the first attribute any new adventurer should train."<<endl;
cout <<"High wis results in more practice sessions per level, which"<<endl;
cout <<"allows quicker training of other attributes and spells/skills."<<endl;
cout <<" "<<endl;
cout <<"Constitution controls how quickly a character can heal. Higher"<<endl;
cout <<"constitution means quicker hp/moves recovery, AND a higher HP gain"<<endl;
cout <<"when leveling."<<endl;
cout <<"The next thing that we need to take a look at is how much HP, Mana "<<endl;
cout <<"and Movements you will be recieving. Now go ahead and type <score>"<<endl;
cin >> Score;


if (Class = 'W')
{
			  PlayerHP = 15;
			  PlayerMana = 0;
			  PlayerMovement = 15;
			  }
			  else
			  if (Class = 'R')
			  {
							PlayerHP = 10;
							PlayerMana = 0;
							PlayerMovement = 10;
							}
							else 
							if (Class = 'M')
							{
										  PlayerHP = 8;
										  PlayerMana = 10;
										  PlayerMovement = 8;
										  }
										  else
										  if (Class = 'C')
										  {
														PlayerHP = 8;
														PlayerMana = 15;
														PlayerMovement = 8;
														}
														

cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
cout <<" Hp  "<<PlayerHP<<" Mana  "<<PlayerMana<<" Movements  "<<PlayerMovement<<endl;
cout <<"		  Strength: "<<PlayerStrength<<endl;
cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
cout <<"		  Constitution: "<<PlayerConstitution<<endl;

cout <<""<<endl;
cout <<"You will notice that you now have Mana and movement and HP added"<<endl;
cout <<"to your score. "<<endl;
cout <<"Type 1 to go North"<<endl;
cin >> Choice;
if (Choice == '1')
{
		   cout <<"Hello and welcome to my world."<<endl;
		   getch();
			  
system ("pause");
						   


		  
}
}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Another Problem with my program (DUMB ME)

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 03:12 AM

Wow I impressed ilandra, good job, now please tell at what line the code is breaking up?
And I must say about the system("cls"); command that some members here like me, and a lot more didn't know about it.
And the program seems pretty good to me, plaease tell where does it stop?
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,063
  • Joined: 10-May 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 03:53 AM

I don't know where you program is stopping, but I would offer this suggestion.

char PlayerName [20];
char PlayerInput;
char Human;
char Elf;
char Ogre;
char Dwarf;
char Warrior;
char Rogue;
char Mage;
char Cleric;
char Class;
char Race;
char Score;
char Choice;
string PlayerStrength;
string PlayerIntelligence;
string PlayerWisdom;
string PlayerConstitution;
string PlayerDexterity;
string ClassName;
string RaceName;
long int PlayerHP;
long int PlayerMana;
long int PlayerMovement;
long int Kill;


Rather than make a variable for every possibility, I would put these into a struct, such as Race, Class, ect & assign values to them. It looks like you do something similar to this, & there are a lot of variables that go unused. You also didn't set any hit-points or levels. Is this going to be a text based game? These are just some suggestions, it looks like it's going to be great.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,063
  • Joined: 10-May 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 05:24 AM

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <dos.h>
//#include <mem.h>
#include <conio.h>
#include <ctime>
#include <windows.h>
#include <string>
using namespace std;
char PlayerName [20];
char PlayerInput;
char Human;
char Elf;
char Ogre;
char Dwarf;
char Warrior;
char Rogue;
char Mage;
char Cleric;
char Class;
char Race;
char Score;
char Choice;
string PlayerStrength;
string PlayerIntelligence;
string PlayerWisdom;
string PlayerConstitution;
string PlayerDexterity;
string ClassName;
string RaceName;
long int PlayerHP;
long int PlayerMana;
long int PlayerMovement;
long int Kill;
int main() {
	system("color 0B");
	cout<<"Welcome to the RPG game that I am trying to create."<<endl;
	cout<<"I hope that you are ready to play the game.		"<<endl;
	cout<<"___________________________________________________"<<endl;
	cout<<"|												 |"<<endl;
	cout<<"|		 1) Create New Character				 |"<<endl; /* Player Decides to create a character */
	cout<<"|		 2) Exit								 |"<<endl; /* Player doesn't want to play */
	cout<<"|_________________________________________________|"<<endl;
	cin>>Choice;
	if (Choice == '2') {
			   cout<<"Alright if you are sure we are now exiting.\n\n"<<endl;
			   system("pause"); /* Game exits if 2 is chosen */
			   return 0;
	}
	else if (Choice == '1') {
		   cout<<"Great it is time to make your character."<<endl; /* Game progresses if Player chooses 1 */
		   system("pause");
		   system("cls");
		   }
		   cout<<"Adventurer please tell me what your name is: "<<endl;
		   cin>>PlayerName;
		  
		   cout<<PlayerName<<" did I get that right? Y/N "<<endl;
		   cin>>Choice;
		   /*Player doesn't like name or entered it wrong */
		   if (Choice == 'N'||Choice == 'n') {
				cout<<"Sorry for that"<<endl;
				return 0; 
		   } /* Since we break out of the program here, there is no need for an else */
		   /*Player likes name and continues */
		   if (Choice == 'Y'||Choice == 'y') {
				cout<<PlayerName<<" ";
				system("pause");
		   }
			 cout <<"Now we must go and find out your race and class"<<endl;
			 cout <<"_______________________________________________"<<endl;
			 cout <<"|											 |"<<endl;
			 cout <<"|	   (W)arrior							 |"<<endl; /* Player picks warrior */
			 cout <<"|	   Žogue							   |"<<endl; /* Player picks rogue */
			 cout <<"|	   (M)age								|"<<endl; /* Player picks mage */
			 cout <<"|	   Šleric							  |"<<endl; /* Player picks cleric */
			 cout <<"|_____________________________________________|"<<endl;
			 cin >> Class; /* Player enters the class */

			 Class=toupper(Class);
			 switch(Class) {
				case 'W':
					ClassName="Warrior";
					PlayerStrength = '8';
					PlayerDexterity = '8';
					PlayerConstitution = '8';
					PlayerWisdom = '8';
					PlayerIntelligence = '8';
					  PlayerHP = 15;
					  PlayerMana = 0;
					  PlayerMovement = 15;
					break;
				case 'R':
					ClassName="Rouge";
					PlayerStrength = '8';
					PlayerDexterity = '8';
					PlayerConstitution = '8';
					PlayerWisdom = '8';
					PlayerIntelligence = '8';
					PlayerHP = 10;
					PlayerMana = 0;
					PlayerMovement = 10;
					break;
				case 'M':
					ClassName="Mage";
					PlayerStrength = '8';
					PlayerDexterity = '8';
					PlayerConstitution = '8';
					PlayerWisdom = '8';
					PlayerIntelligence = '8';
					PlayerHP = 8;
					PlayerMana = 10;
					PlayerMovement = 8;
					break;
				case 'C':
					ClassName="Cleric";
					PlayerStrength = '8';
					PlayerDexterity = '8';
					PlayerConstitution = '8';
					PlayerWisdom = '8';
					PlayerIntelligence = '8';
					PlayerHP = 8;
					PlayerMana = 15;
					PlayerMovement = 8;
					break;

				default :
					ClassName="blank";
			 }

cout <<"Here is how you look so far: \n"<<PlayerName<<" the "<<ClassName<<endl;
system("pause");
cout << "\n\n Please pick a race from the following: "<<endl;
cout <<"______________________________________________"<<endl;
cout <<"|											|"<<endl;
cout <<"|		  (H)uman						   |"<<endl; /* Player picks human race */
cout <<"|		  (E)lf							 |"<<endl; //Player picks elf race
cout <<"|		  (O)gre							|"<<endl; // Player picks ogre race
cout <<"|		  (D)warf						   |"<<endl; // Player picks dwarf race
cout <<"|____________________________________________|"<<endl;
cin >> Race;
Race=toupper(Race);
switch(Race) {
	case 'H':
		RaceName="Human";
		break;
	case 'E':
		RaceName="Elf";
		break;
	case 'O':
		RaceName="Orc";
		break;
	case 'D':
		RaceName="Dwarf";
		break;
	default:
		RaceName="Unknown";
}

system("color F0");
cout <<PlayerName<<" "<<ClassName<<" "<<RaceName<<endl;
cout <<"You are standing in the middle of a room that is"<<endl;
cout <<"Very well lit. Off to one side there is a desk"<<endl;
cout <<"behind the desk sits and older woman who beckons you"<<endl;
cout <<"Goodafternoon "<<PlayerName<<" my name is Deirdre and I am the"<<endl;
cout <<"tutorial secretary. Do you need to know how to play the game?<Y/N>"<<endl;
cin >> Choice;
if (Choice == 'N' || Choice == 'n')
{
	cout << "Going straight to program not yet implimented";
	cout << "Program is exiting";
getch();
		   return 0;
}
else
if (Choice == 'Y' || Choice == 'y')
{
system ("cls");
cout << "The first thing that we are going to do is to take a look"<<endl;
cout << "at your score. To do this type <score>"<<endl;
cin >>Score;
cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
cout <<"		  Strength: "<<PlayerStrength<<endl;
cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
cout <<"		  Constitution: "<<PlayerConstitution<<endl;

cout <<"Let us take a look at your stats first and foremost."<<endl;
cout <<"The first thing that you will notice is Strength which"<<endl;
cout <<"will determine a various list of things including how"<<endl;
cout <<"much you can carry. Higher strength can also increase"<<endl;
cout <<"damroll, resulting in higher damage to the enemy."<<endl;
cout <<" "<<endl;
cout <<"Your dexterity is especially important to rogues"<<endl;
cout <<"nimble fingers help when stealing. But for all"<<endl;
cout <<"classes, Dex improves the character's ability to"<<endl;
cout <<" hold many items, and improves the overall AC, or armor class."<<endl;
cout <<"Intelligence is an attribute that is as important to a mage as"<<endl;
cout <<"it is to a  cleric. Higher intelligence results in more mana "<<endl;
cout <<"gained per level, and allows all classes to learn skills and "<<endl;
cout <<"spells with fewer practices."<<endl;
cout <<" "<<endl;
system ("pause");
system ("cls");
cout <<"Wisdom is the first attribute any new adventurer should train."<<endl;
cout <<"High wis results in more practice sessions per level, which"<<endl;
cout <<"allows quicker training of other attributes and spells/skills."<<endl;
cout <<" "<<endl;
cout <<"Constitution controls how quickly a character can heal. Higher"<<endl;
cout <<"constitution means quicker hp/moves recovery, AND a higher HP gain"<<endl;
cout <<"when leveling."<<endl;
cout <<"The next thing that we need to take a look at is how much HP, Mana "<<endl;
cout <<"and Movements you will be recieving. Now go ahead and type <score>"<<endl;
cin >> Score;


cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
cout <<" Hp  "<<PlayerHP<<" Mana  "<<PlayerMana<<" Movements  "<<PlayerMovement<<endl;
cout <<"		  Strength: "<<PlayerStrength<<endl;
cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
cout <<"		  Constitution: "<<PlayerConstitution<<endl;

cout <<""<<endl;
cout <<"You will notice that you now have Mana and movement and HP added"<<endl;
cout <<"to your score. "<<endl;
cout <<"Type 1 to go North"<<endl;
cin >> Choice;
if (Choice == '1') {
		   cout <<"Hello and welcome to my world."<<endl;
		   getch();
			  
system ("pause");
}
}
}


I cleaned up the multi ifs, & changed them to switch case statments.

It runs through completion for me.
Was This Post Helpful? 0
  • +
  • -

#5 ilandra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 03-August 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 08:45 AM

Alright the problem that I am having is that before it gives you the option to go north it completely cuts out on me at about.
cout <<"Constitution controls how quickly a character can heal.Higher"<<endl;
cout <<"constitution means quicker hp/moves recovery, AND a higher HP gain"<<endl;
cout <<"when leveling."<<endl;
cout <<"The next thing that we need to take a look at is how much HP, Mana "<<endl;
cout <<"and Movements you will be recieving. Now go ahead and type <score>"<<endl;
cin >> Score;

I don't know why it is cutting out here and not continuing with the rest of the program. Do I have to much code on one file? Should I put in more files and link them together? If so how do I link the different codes together so that they work together?
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,063
  • Joined: 10-May 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 08:58 AM

I'm still looking over your code. One thing that I'm finding throughout the code is you issue an if, exit, else continue. If the value (choice) made by the user is to exit the program, then there isn't a need for an else (& more if checking on the value) otherwise, that code wouldn't have been reached.

Here is an example:
   if (Choice == '2') {
			   cout<<"Alright if you are sure we are now exiting.\n\n"<<endl;
			   system("pause"); /* Game exits if 2 is chosen */
			   return 0;
	}
	/* else if (Choice == '1') { */
/* 
There is no need for an else 
since we would never reach this code 
if option 2 was selected 
*/



This will keep you from having all of your program inside of one giant if statement.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5246
  • View blog
  • Posts: 27,063
  • Joined: 10-May 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 10:26 AM

Here is what I have so far, works fine to completion. I would still like to add all the attributes to a struct so you could easily add in NPC or enimies.

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <dos.h>
//#include <mem.h>
#include <conio.h>
#include <ctime>
#include <windows.h>
#include <string>
using namespace std;

/* Begin Functions */
void PickName(void);
void PickRace(void);
void PickClass(void);
void GiveInstructions(void);
/* End Functions */

/* Begin Global Variables */
char PlayerName [20];
char PlayerInput;
char Human;
char Elf;
char Ogre;
char Dwarf;
char Warrior;
char Rogue;
char Mage;
char Cleric;
char Class;
char Race;
char Score;
char Choice;
string PlayerStrength;
string PlayerIntelligence;
string PlayerWisdom;
string PlayerConstitution;
string PlayerDexterity;
string ClassName;
string RaceName;
long int PlayerHP;
long int PlayerMana;
long int PlayerMovement;
long int Kill;
/* End Global Variables */

int main(void) {
	/* Begin Local Variables */
	int done=0; /* used for Y/N options */
	/* End Local Variables */

	system("color 0B");
	cout<<"Welcome to the RPG game that I am trying to create."<<endl;
	cout<<"I hope that you are ready to play the game.		"<<endl;
	cout<<"___________________________________________________"<<endl;
	cout<<"|												 |"<<endl;
	cout<<"|		 1) Create New Character				 |"<<endl; /* Player Decides to create a character */
	cout<<"|		 2) Exit								 |"<<endl; /* Player doesn't want to play */
	cout<<"|_________________________________________________|"<<endl;
	cin>>Choice;
	if(Choice == '2') {
		cout<<"Alright if you are sure we are now exiting.\n\n"<<endl;
		/* The following code is from Xing, via dreamincode.net */
		fflush(stdout);
		(void)getchar();
		return 0;
	}
	cout<<"Great it is time to make your character."<<endl; /* Game progresses if Player chooses 1 */
	system("pause");
	system("cls");
	PickName();
	PickRace();
	PickClass();

	while(done!=1) { /* We need to double check the value of Choice to insure it is Y or N */
		system("color F0");
		system ("cls");
		cout <<PlayerName<<" "<<ClassName<<" "<<RaceName<<endl;
		cout <<"You are standing in the middle of a room that is"<<endl;
		cout <<"Very well lit. Off to one side there is a desk"<<endl;
		cout <<"behind the desk sits and older woman who beckons you"<<endl;
		cout <<"Goodafternoon "<<PlayerName<<" my name is Deirdre and I am the"<<endl;
		cout <<"tutorial secretary. Do you need to know how to play the game?<Y/N>"<<endl;
		cin >> Choice;
		Choice=toupper(Choice);
		if(Choice == 'N') {
			done=1;
			cout << "Going straight to program not yet implimented"<<endl;
			cout << "Program is exiting<<endl";
			getch();
			return 0;
		}
		if(Choice == 'Y') {
			system ("cls");
			done=1;
			GiveInstructions();
		}
	}
	done=0;
}

void PickName(void) {
	int done=0;
	cout<<"Adventurer please tell me what your name is: "<<endl;
	cin>>PlayerName;
	/* We need to make sure the user did not type in more than the default size of PlayerName */
	while(done!=1) {
		cout<<PlayerName<<" did I get that right? Y/N "<<endl;
		cin>>Choice;
		Choice=toupper(Choice);		
		if(Choice == 'N') { /*Player doesn't like name or entered it wrong */
			cout<<"Sorry for that"<<endl;
			Choice='\0';
			PickName();
		} /* Since we break out of the program here, there is no need for an else */
		if(Choice == 'Y') { /*Player likes name and continues */
			done=1;
			cout<<PlayerName<<" ";
		}
	}
}

void PickRace(void) {
	cout <<"Now we must go and find out your race and class"<<endl;
	cout <<"_______________________________________________"<<endl;
	cout <<"|											 |"<<endl;
	cout <<"|	   (W)arrior							 |"<<endl; /* Player picks warrior */
	cout <<"|	   Žogue							   |"<<endl; /* Player picks rogue */
	cout <<"|	   (M)age								|"<<endl; /* Player picks mage */
	cout <<"|	   Šleric							  |"<<endl; /* Player picks cleric */
	cout <<"|_____________________________________________|"<<endl;
	cin >> Class; /* Player enters the class */

	Class=toupper(Class);
	switch(Class) {
	case 'W':
		ClassName="Warrior";
		PlayerStrength = '8';
		PlayerDexterity = '8';
		PlayerConstitution = '8';
		PlayerWisdom = '8';
		PlayerIntelligence = '8';
		PlayerHP = 15;
		PlayerMana = 0;
		PlayerMovement = 15;
		break;
	case 'R':
		ClassName="Rouge";
		PlayerStrength = '8';
		PlayerDexterity = '8';
		PlayerConstitution = '8';
		PlayerWisdom = '8';
		PlayerIntelligence = '8';
		PlayerHP = 10;
		PlayerMana = 0;
		PlayerMovement = 10;
		break;
	case 'M':
		ClassName="Mage";
		PlayerStrength = '8';
		PlayerDexterity = '8';
		PlayerConstitution = '8';
		PlayerWisdom = '8';
		PlayerIntelligence = '8';
		PlayerHP = 8;
		PlayerMana = 10;
		PlayerMovement = 8;
		break;
	case 'C':
		ClassName="Cleric";
		PlayerStrength = '8';
		PlayerDexterity = '8';
		PlayerConstitution = '8';
		PlayerWisdom = '8';
		PlayerIntelligence = '8';
		PlayerHP = 8;
		PlayerMana = 15;
		PlayerMovement = 8;
		break;

	default :
		ClassName="blank";
	}
}

void PickClass(void) {
	cout <<"Here is how you look so far: \n"<<PlayerName<<" the "<<ClassName<<endl;
	system("pause");
	cout << "\n\n Please pick a race from the following: "<<endl;
	cout <<"______________________________________________"<<endl;
	cout <<"|											|"<<endl;
	cout <<"|		  (H)uman						   |"<<endl; /* Player picks human race */
	cout <<"|		  (E)lf							 |"<<endl; //Player picks elf race
	cout <<"|		  (O)gre							|"<<endl; // Player picks ogre race
	cout <<"|		  (D)warf						   |"<<endl; // Player picks dwarf race
	cout <<"|____________________________________________|"<<endl;
	cin >> Race;
	Race=toupper(Race);
	switch(Race) {
		case 'H':
			RaceName="Human";
			break;
		case 'E':
			RaceName="Elf";
			break;
		case 'O':
			RaceName="Orc";
			break;
		case 'D':
			RaceName="Dwarf";
			break;
		default:
			RaceName="Unknown";
	}
	Choice='\0';
}

void GiveInstructions(void) {
	cout << "The first thing that we are going to do is to take a look"<<endl;
	cout << "at your score. To do this type <score>"<<endl;
	cin >>Score;
	cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
	cout <<"		  Strength: "<<PlayerStrength<<endl;
	cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
	cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
	cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
	cout <<"		  Constitution: "<<PlayerConstitution<<endl;

	cout <<"Let us take a look at your stats first and foremost."<<endl;
	cout <<"The first thing that you will notice is Strength which"<<endl;
	cout <<"will determine a various list of things including how"<<endl;
	cout <<"much you can carry. Higher strength can also increase"<<endl;
	cout <<"damroll, resulting in higher damage to the enemy."<<endl;
	cout <<" "<<endl;
	cout <<"Your dexterity is especially important to rogues"<<endl;
	cout <<"nimble fingers help when stealing. But for all"<<endl;
	cout <<"classes, Dex improves the character's ability to"<<endl;
	cout <<" hold many items, and improves the overall AC, or armor class."<<endl;
	cout <<"Intelligence is an attribute that is as important to a mage as"<<endl;
	cout <<"it is to a  cleric. Higher intelligence results in more mana "<<endl;
	cout <<"gained per level, and allows all classes to learn skills and "<<endl;
	cout <<"spells with fewer practices."<<endl;
	cout <<" "<<endl;
	system ("pause");
	system ("cls");
	cout <<"Wisdom is the first attribute any new adventurer should train."<<endl;
	cout <<"High wis results in more practice sessions per level, which"<<endl;
	cout <<"allows quicker training of other attributes and spells/skills."<<endl;
	cout <<" "<<endl;
	cout <<"Constitution controls how quickly a character can heal. Higher"<<endl;
	cout <<"constitution means quicker hp/moves recovery, AND a higher HP gain"<<endl;
	cout <<"when leveling."<<endl;
	cout <<"The next thing that we need to take a look at is how much HP, Mana "<<endl;
	cout <<"and Movements you will be recieving. Now go ahead and type <score>"<<endl;
	cin >> Score;

	cout <<"\n\n\n"<<PlayerName<<"   "<<ClassName<<"   "<<RaceName<<endl;
	cout <<" Hp  "<<PlayerHP<<" Mana  "<<PlayerMana<<" Movements  "<<PlayerMovement<<endl;
	cout <<"		  Strength: "<<PlayerStrength<<endl;
	cout <<"		  Dexterity: "<<PlayerDexterity<<endl;
	cout <<"		  Wisdom: "<<PlayerWisdom<<endl;
	cout <<"		  Intelligence: "<<PlayerIntelligence<<endl;
	cout <<"		  Constitution: "<<PlayerConstitution<<endl;

	cout <<""<<endl;
	cout <<"You will notice that you now have Mana and movement and HP added"<<endl;
	cout <<"to your score. "<<endl;
	cout <<"Type 1 to go North"<<endl;
	cin >> Choice;
	if(Choice == '1') {
		cout <<"Hello and welcome to my world."<<endl;
		getch();
		system ("pause");
	}
}


Was This Post Helpful? 0
  • +
  • -

#8 csmanoj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 06-August 07

Re: Another Problem with my program (DUMB ME)

Posted 07 August 2007 - 08:54 PM

Quote

nimble fingers help when stealing. But for all
classes, Dex improves the character's ability to
hold many items, and improves the overall AC, or armor class.
Intelligence is an attribute that is as important to a mage as
it is to a cleric. Higher intelligence results in more mana
gained per level, and allows all classes to learn skills and
spells with fewer practices.

Press any key to continue . . .


The program runs until that in my PC. Is that what you intended? And there is no game loop. It is bound to exit somewhere. I would suggest that you use a loop between all the "Press any key to continue...". That will give you a clearer game code.

If you just want to get it working right, I would say you should just change the variable type of 'Score' to string. That will solve your problem.


But I still recommend you rewrite the program neatly and following conventions. And more importantly, stop calling system(). It's bad practice. Put a game loop. It's the best way to make games.

This post has been edited by csmanoj: 07 August 2007 - 09:10 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1