Structures, cin, and functions

What's the best way to do this?

Page 1 of 1

9 Replies - 1161 Views - Last Post: 17 September 2007 - 05:11 AM Rate Topic: -----

#1 Syntax_Terror  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 03-September 07

Structures, cin, and functions

Posted 08 September 2007 - 02:18 PM

#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <sstream>

using namespace std;
string order;
int direction,move=1;
int loc =0;
int x,y=11;
string ROOM []={};
string shdesc[]={"You're in the north plaza.", 
"You're in the arena.",						
"You're in the equipment shop.",			   
"You're in the temple.",					   
"You're in the tavern.",					   
"You're in the weapon shop.",				  
"You're in the armor shop.",				   
"You're in the guild hall.",				   
"You're in the magic shop.",				   
"You're in the south plaza.",				  
"You're on the docks."
};
string lngdesc[]={"You are standing at the north end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges whose scent wafts through the warm, dry air. To the west stands an ornate temple adorned with ornate stone and brass architecture. A quaint little shop lies to the northwest, and a dimly lit, smokey little tavern to the northeast. To the east lay the huge wrought iron gates of the arena. To north is the town guild hall. The other half of the plaza lies to the south.",
"You now stand inside the gates of the village's most noteworthy and notorious point of interest, the arena. The charred and stained stone walls and scattered bits of bone, armor, and weaponry lying among the debris on the packed earthen floor. A huge brass gong hangs at the center of the arena suspended on a framework made of the bones of some of the less fortunate of the arena's combatants. To the south is a wide stone staircase leading down to the dungeon gate. The exit through the arena gates is to the west.",
"You are now inside the equipment shop, where one may purchase supplies and provisions essential to survival in the dungeons or the wilderness. The shop keeper sits on a tall stool behind a counter along the north wall, eyeing you warily. The exit is to the southeast.",
"You are now in the main entry hall of a great temple. Huge black marble columns veined with platinum stretch to the ceiling some 100' overhead. The patterns in the tile floor are so ornate and complex as to be nearly impossible to follow or comprehend. Many black silk tapestries depicting various scenes of a religious or magical nature block your view into the many other areas of the temple. Blue robed priests and acolytes move here and there going about their daily duties. The exit is to the east.",
"You are in the village tavern. The smoke from the many oil lamps decrease visibility to your immediate surroundings, and the wavering light they cast about the room leaves many shadows and unlit corners. There are several tables about the room, where the tavern's patrons eat, drink, and generally enjoy themselves. The bar stands along the north wall and a door to the kitchen lies to the northeast. A large, full length mirror adorns the west wall. The only visible exits lie up a steep wooden ladder near the rear of the room, and out into the north plaza to the southwest.",
"You are now inside the weapon shop, where you may purchase various weapons to use for sparring in the arena or for personal defense from the denizens of the dungeons. The shop keeper sits on a high stool behind a tall counter along the south wall. The exit is to the west. ",
"You are now inside the armor shop, where you may acquire different sorts of armor and protective gear to guard yourself against the blows of your opponents in the arena, or from the various non-human foes to be found in the dungeons beneath the town. The shop keeper sits on a high behind a worn counter along the south wall, eyeing you warily. The exit is to the east.",
"You have entered the town guild hall, where one may seek the training necessary to refine your combat and spell skills. This building is also a center of learning where the ancient art of sorcery is taught to those with the intelligence and skill to wield it effectively. Mages, wizards, and masters-at-arms rush about on errands or to and from training sessions. Ornately carved marble archways exit to the north and south, and a wide stone staircase leads downward.",
"You're standing in a warm, dimly lit shop where various magical items are bought and sold by a shrewd mage in crimson robes with an air of power and complete confidence about him. He doesn't look like someone whose spells you'd like to be on the wrong end of. The sweet scent of incense drifts in from a workroom in the rear of the shop. The exit is to the north.",
"You are standing at the south end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges who's scent wafts through the warm, dry air. To the west stands the town's armor shop. The weapon shop lies to the east. There is a magic shop to the south. To the north lies the other half of the plaza and to the southwest lies the town's outer gate.",
"You are standing on the docks. The water from the lake laps quietly against the docks making the peaceful scene on the lake all that more serene. An ornately carved marble archway exits through the town wall to the south into the guild hall."
};

int room [11][11]={	 
		{0,8,10,2,4,5,3,0,0,0,0},
		{0,0,0,1,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,1,0,0,0},
		{0,0,0,1,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,1,0,0},
		{0,0,0,10,0,0,0,0,0,0,0},
		{0,0,10,0,0,0,0,0,0,0,0},
		{0,11,1,0,0,0,0,0,0,0,0},
		{0,10,0,0,0,0,0,0,0,0,0},
		{0,1,9,6,7,0,0,0,0,0,0},
		{0,0,8,0,0,0,0,0,0,0,0}
		};

int main(int argc, char *argv[]) 
{	 
		// Display short room desc, and promput
cout << shdesc[loc]<<endl;
cout << ">";
		// Ask for user input
cin > order;
		//Need a routine to convert input to lowercase here


		// Convert direction to a number (re-write routine later, make into function)

if (order=="n"){
cout << "You went north"<<endl;
direction=1;
};
if (order=="s"){
cout << "You went south"<<endl;
direction=2;
};
if (order=="e"){
cout << "You went east"<<endl;
direction=3;
};
if (order=="w"){
cout << "You went west"<<endl;
direction=4;
};
if (order=="ne"){
cout << "You went northeast"<<endl;
direction=5;
};
if (order=="nw"){
cout << "You went northwest"<<endl;
direction=6;
};
if (order=="se"){
cout << "You went southeast"<<endl;
direction=7;
};
if (order=="sw"){
cout << "You went southwest"<<endl;
direction=8;
};
if (order=="u"){
cout << "You went up"<<endl;
direction=9;
};
if (order=="d"){
cout << "You went down"<<endl;
direction=10;
};
move=room[loc] [direction];
loc=move;
cout << shdesc[loc]<<endl;
	system("PAUSE");	
	return 0;
}



When I compile this I get:

No match for IO_ISTREAM_withasign&> string&'

ok... I'm sure that's not all that big... These are the topics I'd like to hit.

1. How can I structure the data better?
2. What's the difference between static / dynamic arrays, and which one do I need here? (I was told I needed static by 1 person and dynamic by another)
3. How can I make a function and condense all those "if" statements?
4. Do I need all those "include" statements at the top?

Please keep in mind, I'm a truck driver, and though I've been interested in C++ for 6 weeks, I only get to my computer about an hour a week, so I'm a 6 hour c++ vet... grin

Is This A Good Question/Topic? 0
  • +

Replies To: Structures, cin, and functions

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Structures, cin, and functions

Posted 08 September 2007 - 04:23 PM

First thing you'll want to do is remove the semi colons at the ens of each closing brace of your if constructs:
if (order=="n"){
cout << "You went north"<<endl;
direction=1;
};


should be
if (order=="n"){
cout << "You went north"<<endl;
direction=1;
}


You may also want to switch the if statements to a select case statement, since you're really only checking a single character.

A dynamic array is one whose size is decided after the program begins to run, or may need to be changed during program execution. If you will be adding additional information to the array (any array) during runtime, then dynamic arrays are the way to go. If the arrays will stay the same as when a program begins, a static array is fine.

Your actual compiler error is here:
cin > order;


The operator is >>, not >.

Based on the code you currently have, you do not all of the includes you have...but that's not to say you won;t be adding other code that may require those libraries.
Was This Post Helpful? 0
  • +
  • -

#3 Syntax_Terror  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 03-September 07

Re: Structures, cin, and functions

Posted 10 September 2007 - 01:46 PM

Thanks! That was a great fix. I didn't take your advice on the 'select case', rather chose another option, I hope will work out a little better, as I add in more and more command options. Eventually I am going to take "order", and break it up into two words, verb, and noun, and jump to the function to handle the verb. Inside those function I think your "select case" option would be best. I think you're just running 3 steps ahead of me. :) Revised (ahem) code:

#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <sstream>

using namespace std;
string order;
int i=0;
int direction,move=1;
int loc =1;
int x,y=0;
string ROOM []={};
string shdesc[]={"You are nowhere.",
"You're in the north plaza.", 
"You're in the arena.",						
"You're in the equipment shop.",			   
"You're in the temple.",					   
"You're in the tavern.",					   
"You're in the weapon shop.",				  
"You're in the armor shop.",				   
"You're in the guild hall.",				   
"You're in the magic shop.",				   
"You're in the south plaza.",				  
"You're on the docks."
};
string lngdesc[]={"You are nowhere.",
"You are standing at the north end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges whose scent wafts through the warm, dry air. To the west stands an ornate temple adorned with ornate stone and brass architecture. A quaint little shop lies to the northwest, and a dimly lit, smokey little tavern to the northeast. To the east lay the huge wrought iron gates of the arena. To north is the town guild hall. The other half of the plaza lies to the south.",
"You now stand inside the gates of the village's most noteworthy and notorious point of interest, the arena. The charred and stained stone walls and scattered bits of bone, armor, and weaponry lying among the debris on the packed earthen floor. A huge brass gong hangs at the center of the arena suspended on a framework made of the bones of some of the less fortunate of the arena's combatants. To the south is a wide stone staircase leading down to the dungeon gate. The exit through the arena gates is to the west.",
"You are now inside the equipment shop, where one may purchase supplies and provisions essential to survival in the dungeons or the wilderness. The shop keeper sits on a tall stool behind a counter along the north wall, eyeing you warily. The exit is to the southeast.",
"You are now in the main entry hall of a great temple. Huge black marble columns veined with platinum stretch to the ceiling some 100' overhead. The patterns in the tile floor are so ornate and complex as to be nearly impossible to follow or comprehend. Many black silk tapestries depicting various scenes of a religious or magical nature block your view into the many other areas of the temple. Blue robed priests and acolytes move here and there going about their daily duties. The exit is to the east.",
"You are in the village tavern. The smoke from the many oil lamps decrease visibility to your immediate surroundings, and the wavering light they cast about the room leaves many shadows and unlit corners. There are several tables about the room, where the tavern's patrons eat, drink, and generally enjoy themselves. The bar stands along the north wall and a door to the kitchen lies to the northeast. A large, full length mirror adorns the west wall. The only visible exits lie up a steep wooden ladder near the rear of the room, and out into the north plaza to the southwest.",
"You are now inside the weapon shop, where you may purchase various weapons to use for sparring in the arena or for personal defense from the denizens of the dungeons. The shop keeper sits on a high stool behind a tall counter along the south wall. The exit is to the west. ",
"You are now inside the armor shop, where you may acquire different sorts of armor and protective gear to guard yourself against the blows of your opponents in the arena, or from the various non-human foes to be found in the dungeons beneath the town. The shop keeper sits on a high behind a worn counter along the south wall, eyeing you warily. The exit is to the east.",
"You have entered the town guild hall, where one may seek the training necessary to refine your combat and spell skills. This building is also a center of learning where the ancient art of sorcery is taught to those with the intelligence and skill to wield it effectively. Mages, wizards, and masters-at-arms rush about on errands or to and from training sessions. Ornately carved marble archways exit to the north and south, and a wide stone staircase leads downward.",
"You're standing in a warm, dimly lit shop where various magical items are bought and sold by a shrewd mage in crimson robes with an air of power and complete confidence about him. He doesn't look like someone whose spells you'd like to be on the wrong end of. The sweet scent of incense drifts in from a workroom in the rear of the shop. The exit is to the north.",
"You are standing at the south end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges who's scent wafts through the warm, dry air. To the west stands the town's armor shop. The weapon shop lies to the east. There is a magic shop to the south. To the north lies the other half of the plaza and to the southwest lies the town's outer gate.",
"You are standing on the docks. The water from the lake laps quietly against the docks making the peaceful scene on the lake all that more serene. An ornately carved marble archway exits through the town wall to the south into the guild hall."
};
string dir[]={"zz",
"n",
"s",
"e",
"w",
"ne",
"nw",
"se",
"sw",
"u",
"d"
};
string comp[]={"nowhere",
"north",
"south",
"east",
"west",
"northeast",
"northwest",
"southeast",
"southwest",
"up",
"down",
};

int room [12][11]={	 
		{0,0,0,0,0,0,0,0,0,0},
		{0,8,10,2,4,5,3,0,0,0},
		{0,0,0,0,1,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,1,0,0,0},
		{0,0,0,1,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,1,0,0},
		{0,0,0,0,10,0,0,0,0,0,0},
		{0,0,0,10,0,0,0,0,0,0,0},
		{0,11,1,0,0,0,0,0,0,0,0},
		{0,10,0,0,0,0,0,0,0,0,0},
		{0,1,9,6,7,0,0,0,0,0,0},
		{0,0,8,0,0,0,0,0,0,0,0}
		};




int main(int argc, char *argv[]) 
{	 

		// Display short room desc, and prompt for parser
cout << shdesc[loc]<<endl;
cout << ">";
		// Ask for user input
cin >> order;
		//Need to add a routine to convert input to lowercase here


// move to new room
for (i=1;i<10;i++){
if ((order==dir[i]) || (order==comp[i])){
direction=i;
}
}
move=room[loc] [direction];
loc=move;
cout << "You went " << comp [direction] << endl;
cout << shdesc[loc]<<endl;


	system("PAUSE");	
	return 0;
}



Now, if I do everything in "main" which as I understand it, is basically a function itself, can I add, and call other functions within 'main'?
I need to get the "cin >> order;" command to loop back onto itself, get your input, turn it to lowercase, move you to another room, display the info, and go back to the "cin >> order;" again.

May I ask, how would that best be structured and achieved?
Was This Post Helpful? 0
  • +
  • -

#4 mondauthor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 08-September 07

Re: Structures, cin, and functions

Posted 10 September 2007 - 04:22 PM

Hi ST,
No offense, but it would be best if you could learn the basics of the language through a tutorial. Your questions indicate that you haven't done the work necessary to understand the most basic features of the language.

I went through Juan Soulie's C++ Tutorials on cplusplus.com just to get started. But to answer one of your questions, an infinite Do While loop with a Switch is great for taking in data from a user and having your application act on that data.

do{
//take data from player
switch (data)
{
case 1: //program does something
case 2: //program does something different
case 3: //etc......
}//end of switch statement
}while(TRUE);

It is not that people don't want to help you, it is that they expect you to do the work to get the basics for yourself.

Mond
Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Structures, cin, and functions

Posted 10 September 2007 - 04:27 PM

I usually advise against infinite loops - what will be your break condition? Under what circumstance do you want the use to stop being prompted for input.
Was This Post Helpful? 0
  • +
  • -

#6 Syntax_Terror  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 03-September 07

Re: Structures, cin, and functions

Posted 11 September 2007 - 12:45 PM

View Postmondauthor, on 10 Sep, 2007 - 04:22 PM, said:

Hi ST,
No offense, but it would be best if you could learn the basics of the language through a tutorial. Your questions indicate that you haven't done the work necessary to understand the most basic features of the language.
...

...It is not that people don't want to help you, it is that they expect you to do the work to get the basics for yourself.

Mond



Certainly, no offense is taken... However understand this. I asked no one for anything more than their opinion. I was greatful, and thrilled when I got a reply at all, much less so quickly. I asked no one to write a single character of code or rewrite anything I've done.

I do try to do my own own work, but when you get started in a language such as C++, and have a schedule such as mine (my problem I know), it's best in my opinion if you can ask, and consult with the pros. Sometimes... the basics don't come as easy to some as they do to others, but when they do come, they come fast and hard, and sometimes they don't ever come. I would never throw you the keys and manual to a Semi, and tell you to go learn the "basics" then come ask me questions. By then people would be dead. With the size of the program I intended to write, I felt that I should consult, and get advice, instead of writing a huge file only to have tear it apart and re-do it. If you feel I'm not qualified to ask a damnn question, then do me a favor, and don't reply... I thought I was doing pretty good for only having actually a day or two on hand experience.
However, I will endeavor to make sure any future questions are on a tenth year super genius, physicist level for you since my other question was to stupid, and low of a level to be acceptable enough for you. Thanks for the advice, and have a great day!! :)
Was This Post Helpful? 0
  • +
  • -

#7 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Structures, cin, and functions

Posted 11 September 2007 - 12:49 PM

Hi Syntax_Terror,

I would like to let you know that you should feel free to ask any question you wish (well, related to C/C++ in this forum). We are here to help all levels of programmers, from novice to expert. While we do ask that user's 'show their work' as it were, you have done so as per policy.

Ask any question at all...our members would be pleased to help.
Was This Post Helpful? 0
  • +
  • -

#8 Syntax_Terror  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 03-September 07

Re: Structures, cin, and functions

Posted 14 September 2007 - 07:44 AM

View PostAmadeus, on 11 Sep, 2007 - 12:49 PM, said:

Hi Syntax_Terror,

I would like to let you know that you should feel free to ask any question you wish (well, related to C/C++ in this forum). We are here to help all levels of programmers, from novice to expert. While we do ask that user's 'show their work' as it were, you have done so as per policy.

Ask any question at all...our members would be pleased to help.


Thanks... I wasn't upset, just the smart alec in me had to rear his ugly head on that one. :)

Ok, on to business...

I've got everything working. I trashed the variable order, and did my "verb & noun" thing, it converts my input to lowercase, and goes to the proper function. I'll start working on this when I get back next week...
However, when I compile & run, I do get a weird error saying my compiler needs to shut down, and it wants to report the error to microsoft... I hit "don't send", and it continues on just fine. I am using DEV-C compiler.
I was wondering if anyone could see any reason for this error. I checked the compiler with about a dozen other codes, and it is working great. I think it must be something I have done in my.... uh... code... (for lack of a better word.) Also, I am wide open to any suggestions to improve what I have... especially from you Mondauthor, I do value your opinion, atleast you are honest... :)

Any ideas, on how I can start to get this thing to loop back to the verb/noun input in the main ?

Thank you all, in advance.
ST



#include <iostream>
#include <stdlib.h>
#include <string>
#include <conio.h>
#include <sstream>
using namespace std;
int x,y,i=0;
string verb,noun;
int direction,move=1;
int loc =1;
string ROOM []={};
string shdesc[]={"You are nowhere.",
"You're in the north plaza.", 
"You're in the arena.",						
"You're in the equipment shop.",			   
"You're in the temple.",					   
"You're in the tavern.",					   
"You're in the weapon shop.",				  
"You're in the armor shop.",				   
"You're in the guild hall.",				   
"You're in the magic shop.",				   
"You're in the south plaza.",				  
"You're on the docks."
};
string lngdesc[]={"You are nowhere.",
"You are standing at the north end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges whose scent wafts through the warm, dry air. To the west stands an ornate temple adorned with ornate stone and brass architecture. A quaint little shop lies to the northwest, and a dimly lit, smokey little tavern to the northeast. To the east lay the huge wrought iron gates of the arena. To north is the town guild hall. The other half of the plaza lies to the south.",
"You now stand inside the gates of the village's most noteworthy and notorious point of interest, the arena. The charred and stained stone walls and scattered bits of bone, armor, and weaponry lying among the debris on the packed earthen floor. A huge brass gong hangs at the center of the arena suspended on a framework made of the bones of some of the less fortunate of the arena's combatants. To the south is a wide stone staircase leading down to the dungeon gate. The exit through the arena gates is to the west.",
"You are now inside the equipment shop, where one may purchase supplies and provisions essential to survival in the dungeons or the wilderness. The shop keeper sits on a tall stool behind a counter along the north wall, eyeing you warily. The exit is to the southeast.",
"You are now in the main entry hall of a great temple. Huge black marble columns veined with platinum stretch to the ceiling some 100' overhead. The patterns in the tile floor are so ornate and complex as to be nearly impossible to follow or comprehend. Many black silk tapestries depicting various scenes of a religious or magical nature block your view into the many other areas of the temple. Blue robed priests and acolytes move here and there going about their daily duties. The exit is to the east.",
"You are in the village tavern. The smoke from the many oil lamps decrease visibility to your immediate surroundings, and the wavering light they cast about the room leaves many shadows and unlit corners. There are several tables about the room, where the tavern's patrons eat, drink, and generally enjoy themselves. The bar stands along the north wall and a door to the kitchen lies to the northeast. A large, full length mirror adorns the west wall. The only visible exits lie up a steep wooden ladder near the rear of the room, and out into the north plaza to the southwest.",
"You are now inside the weapon shop, where you may purchase various weapons to use for sparring in the arena or for personal defense from the denizens of the dungeons. The shop keeper sits on a high stool behind a tall counter along the south wall. The exit is to the west. ",
"You are now inside the armor shop, where you may acquire different sorts of armor and protective gear to guard yourself against the blows of your opponents in the arena, or from the various non-human foes to be found in the dungeons beneath the town. The shop keeper sits on a high behind a worn counter along the south wall, eyeing you warily. The exit is to the east.",
"You have entered the town guild hall, where one may seek the training necessary to refine your combat and spell skills. This building is also a center of learning where the ancient art of sorcery is taught to those with the intelligence and skill to wield it effectively. Mages, wizards, and masters-at-arms rush about on errands or to and from training sessions. Ornately carved marble archways exit to the north and south, and a wide stone staircase leads downward.",
"You're standing in a warm, dimly lit shop where various magical items are bought and sold by a shrewd mage in crimson robes with an air of power and complete confidence about him. He doesn't look like someone whose spells you'd like to be on the wrong end of. The sweet scent of incense drifts in from a workroom in the rear of the shop. The exit is to the north.",
"You are standing at the south end of a large open plaza surrounded by shade trees as well as assorted flowering shrubs and hedges who's scent wafts through the warm, dry air. To the west stands the town's armor shop. The weapon shop lies to the east. There is a magic shop to the south. To the north lies the other half of the plaza and to the southwest lies the town's outer gate.",
"You are standing on the docks. The water from the lake laps quietly against the docks making the peaceful scene on the lake all that more serene. An ornately carved marble archway exits through the town wall to the south into the guild hall."
};
string dir[]={"zz",
"n",
"s",
"e",
"w",
"ne",
"nw",
"se",
"sw",
"u",
"d"
};
string comp[]={"nowhere",
" north",
" south",
" east",
" west",
" northeast",
" northwest",
" southeast",
" southwest",
" up",
" down",
};

int room [12][11]={	 
		{0,0,0,0,0,0,0,0,0,0},
		{0,8,10,2,4,5,3,0,0,0},
		{0,0,0,0,1,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,1,0,0,0},
		{0,0,0,1,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0,1,0,0},
		{0,0,0,0,10,0,0,0,0,0,0},
		{0,0,0,10,0,0,0,0,0,0,0},
		{0,11,1,0,0,0,0,0,0,0,0},
		{0,10,0,0,0,0,0,0,0,0,0},
		{0,1,9,6,7,0,0,0,0,0,0},
		{0,0,8,0,0,0,0,0,0,0,0}
		};

string go(){ // Move to a new room
cout << "This is the go function" << endl;
for (i=1;i<10;i++){
cout << comp[i]<<",";
if ((noun==comp[i])){
direction=i;
}
}
move=room[loc] [direction];
loc=move;
cout << "You went " << comp [direction] << endl;
cout << shdesc[loc]<<endl;

}
string light(){
	   cout << "This is the light function";
	   }
string get(){
	   cout << "This is the get function";
}	   

int main(int argc, char *argv[]){

cout <<">";
cin >> verb;
getline (cin,noun); 
//Convert to lowercase
for (int i = 0; i < verb.length(); i++) 
{ 
verb[i] = tolower (verb[i]); 
} 
for (int i = 0; i < noun.length(); i++) 
{ 
noun[i] = tolower (noun[i]); 
}
cout << "Verb :" << verb << "\nNoun :" << noun <<endl; // display for debugging purposes - remove later
cout << "\n\n\n" <<endl; // remove later
if (verb=="go"){
				go();
				}
if (verb=="light"){
				   light();
				   }
if (verb=="get"){
			   get();
			   }
   system("PAUSE");
	return EXIT_SUCCESS;
}


This post has been edited by Syntax_Terror: 14 September 2007 - 07:51 AM

Was This Post Helpful? 0
  • +
  • -

#9 Vextor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 8
  • View blog
  • Posts: 313
  • Joined: 22-May 02

Re: Structures, cin, and functions

Posted 14 September 2007 - 09:18 AM

Well, in order for it to get back to the noun stage where the user is entering their direction you're going to want to use a loop as mondauthor suggested. But, 'infinite' won't necessarilly be the case.

Basically use this idea...

bool doAgain = true;
.
.
.
while(doAgain)
{
   //your code here. But you'll need to check to see if the user wants out of this. Probably by checking 
   //for a specific entry like 'exit'. if exit is typed set doAgain to false to get out of the loop. Otherwise, leave it as true
   //and it will execute the code again.
}



Hope that gets you on the right track. Also, it'll be worthwhile to read up on how to build and implement functions in c++. It'll make your code much more clean and allow for re-usability of common tasks.

This one's not bad C++ Functions

and of course check out DIC there are tons of resources here.
Was This Post Helpful? 0
  • +
  • -

#10 Syntax_Terror  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 204
  • Joined: 03-September 07

Re: Structures, cin, and functions

Posted 17 September 2007 - 05:11 AM

Thanks Vextor...

The bool/ while statements worked fine, once I figured out how to use VOID.... That's great!

I'm sure I could get a much cleaner code, but since I'm learning as I go, and only have "C++ for dummies" as a guide, I think I'll settle for "working" this go around, and next time, I'll try to fine tune the art of C++. :)

Thanks for your help!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1