Hello guys, i would like to ask you about c++ language. have an assignment and i want to do a movement for?
i another questions, the hero should for example take a bomb to destroy the wall , hoe can i disply a message to show the user that what he\she should to do? somebody told me by loop but i couldn't understand : ( please help me and i apologise because my english isn't very well waiting for youi have an assignment and i want to do a movement for the hero which will be controled by the keyboard another questions, the hero should for example take a bomb to destroy the wall , hoe can i disply a message to show the user that what he\she should to do? somebody told me by loop but i couldn't understand : ( please help me and i apologise because my english isn't very well waiting for you

>>hoe can i disply a message to show the user that what he\she should to do?

Maybe by displaying the required insturctions on the screen using stdout. Maybe something like this?

cout << "You now have a bomb that can be used to blow up a wall."

Such instructions and other options for the user to do are frequently placed in a loop so the instructions can be displayed on the fly as opposed to being displayed once at the start of a program or in an instruction booklet. The timing of these displays and displaying the options available to the user can be repeated ad nauseum within a loop so the flow of the "game"/"program" can be controlled, but the display of the instruction to the user during the game is a straightforward process using cout << .

thanks *_^

I tried to do in loop but i coudn't

so can you please show me how in c++ code?

and what about my questions to how can i make the movement:(

There is much more information, for example what options does the user have, what instructions are desired, etc, needed before I could do anything vaguely resembling your request. In general it might end up something like this, though:

bool doMore = true;
while(doMore)
{
    display options here
    get input here
    apply input choice here

    ask whether to continue here
       adjust doMore as appropriate here 
}

yes i know how to do the loop but i don't know how to do the statment : (

can u please do this for me? and i'll study the code

thank you so much

i'll try much to explain to you *_^ , i'm asking the user to press a or w or s or d to move on the map. if he\she press 'w' so the hero must move up, the qustion how to do this by using loop? i'd like to see the code pleaaaaaase

if he\she press 'w' so the hero must move up, the qustion how to do this by using loop?

How about this? Getting the user input and then doing whatever required to move using a switch()?

bool doMore = true;
char input;
while(doMore)
{
    cout << "Choose direction: ";
    cin >> input;

    switch(input)
    {
    case 'W':
        //Move up
        break;
        //etc.
    default: break;
    }

    //To exit the loop - doMore = false;
}

;

wow thank you so much i tested just know and it works very well *_^

bus i'm still have a small problem , for example i have three rooms

which is similar to this:

|------|------|------|
| h
|------|------|------|

h = the hero, d= move right , a= move left ,if the user enter 'd' so i want the hero to move to next room and when the user press 'd' again so the hero should move to the last room , i tried many times just know but i couldn't do it

thank you so much

Are you asking us to write it for you? Or are you asking us to help you correct your code that doesn't work?

If the first, forget it. We are not a coding service.
If the second, great. But we aren't psychic and can't tell what you tried that didn't work unless you show us. Be sure to use CODE tags when you do show us.

#include "PrettyConsole.hpp"
#include <iostream>
using namespace std;

	
	int main()	
	{
		
	
			
	char wall = 177 , flute = 14 , hero = 2 , life = 3 ,villain = 1  , bomb = 15 , fish = 12 ,user_input;
		cout <<" please enter the direaction: " <<endl;
	    cin >> user_input;
	while (user_input)
	{
		cout <<" please enter the direaction: " <<endl;
	    cin >> user_input;
	    
	    switch (user_input)
	    {
	    case 'a':
	    cout <<"-------"<< endl;
		cout <<"legend"<< endl;
		cout <<"-------"<< endl;
		cout <<""<<hero<<" = hero"<< endl;
		cout <<""<<villain<<" = villain"<< endl;
		cout <<""<<fish<<" = pet fish"<< endl;
		cout <<""<<bomb<<" = bomb"<< endl;
		cout <<""<<flute<<" = flute"<< endl;
		cout <<""<< wall <<" = wall"<< endl;
		cout <<"--------------"<< endl;
		cout <<"w = move up"<< endl;
		cout <<"a = mobe left"<< endl;
		cout <<"s = mobe down"<< endl;
		cout <<"d = move right"<< endl;
		cout <<"<spacebar> = get/use item"<< endl;
		cout <<""<< endl;
		cout <<"******************************"<< endl;
		cout <<""<< endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:---------"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":     "<<hero<<""<<bomb<<"             "<< wall <<"         :--------------:"<<endl;        
		cout <<":                    "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :           ___:"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":     "<<hero<<"              "<< wall <<"    "<<villain<<"          "<<fish<<"    :"<<endl;
		cout <<":                    "<< wall <<"                    :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :___"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":                    "<< wall <<"         :--------------:"<<endl;
		cout <<":     "<<flute<<"            "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:--------- "<< endl;
	break;
	
	 case 'm':
	    cout <<"-------"<< endl;
		cout <<"legend"<< endl;
		cout <<"-------"<< endl;
		cout <<""<<hero<<" = hero"<< endl;
		cout <<""<<villain<<" = villain"<< endl;
		cout <<""<<fish<<" = pet fish"<< endl;
		cout <<""<<bomb<<" = bomb"<< endl;
		cout <<""<<flute<<" = flute"<< endl;
		cout <<""<< wall <<" = wall"<< endl;
		cout <<"--------------"<< endl;
		cout <<"w = move up"<< endl;
		cout <<"a = mobe left"<< endl;
		cout <<"s = mobe down"<< endl;
		cout <<"d = move right"<< endl;
		cout <<"<spacebar> = get/use item"<< endl;
		cout <<""<< endl;
		cout <<"******************************"<< endl;
		cout <<""<< endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:---------"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":     "<<bomb<<"              "<< wall <<"         :--------------:"<<endl;        
		cout <<":                    "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :           ___:"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":     "<<hero<<"              "<< wall <<"    "<<villain<<"          "<<fish<<"    :"<<endl;
		cout <<":                    "<< wall <<"                    :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :___"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":                    "<< wall <<"         :--------------:"<<endl;
		cout <<":    "<<flute<<"             "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:--------- "<< endl;
		break;
		
		case 'd':
		cout <<"-------"<< endl;
		cout <<"legend"<< endl;
		cout <<"-------"<< endl;
		cout <<""<<hero<<" = hero"<< endl;
		cout <<""<<villain<<" = villain"<< endl;
		cout <<""<<fish<<" = pet fish"<< endl;
		cout <<""<<bomb<<" = bomb"<< endl;
		cout <<""<<flute<<" = flute"<< endl;
		cout <<""<< wall <<" = wall"<< endl;
		cout <<"--------------"<< endl;
		cout <<"w = move up"<< endl;
		cout <<"a = mobe left"<< endl;
		cout <<"s = mobe down"<< endl;
		cout <<"d = move right"<< endl;
		cout <<"<spacebar> = get/use item"<< endl;
		cout <<""<< endl;
		cout <<"******************************"<< endl;
		cout <<""<< endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:---------"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":     "<<bomb<<"              "<< wall <<"         :--------------:"<<endl;        
		cout <<":                    "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :           ___:"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":     "<<hero<<"              "<< wall <<"    "<<villain<<"          "<<fish<<"    :"<<endl;
		cout <<":                    "<< wall <<"                    :"<<endl;
		cout <<":           :--------+                    :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :          :"<<endl;
		cout <<"+----- -----+\\\\\\\\\\\\\\\\:         :          :___"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :              :"<<endl;
		cout <<":           :--------+         :              :"<<endl;
		cout <<":                    "<< wall <<"         :--------------:"<<endl;
		cout <<":     "<<hero<<""<<flute<<"             "<< wall <<"         :              :"<<endl;
		cout <<":           :--------+         :"<<endl;
		cout <<":           :\\\\\\\\\\\\\\\\:         :"<<endl;
		cout <<"+-----------+\\\\\\\\\\\\\\\\:--------- "<< endl;
	break;
	default:
	
;}
}
	return 0;		
    	}

this is my code, it's not comblete yet

in past i asked for the code because i'd like to study it , not to copy then i can learn and go ahead ^_^

use loops instead of so many cout statments and i don't think the variable in the while loop is defined. I am willing to help you come with the solution if i knew what you were doing. I can't read your mind. Based on your code your don't have a default condition.

That's pretty nice looking.
First, just for the sake of clearity I'd recommend making a function that draws the map.
As such:

#include <iostream>
using namespace std;

void DrawMap()
{
char wall = 177, flute = 14, hero = 2,
      life = 3, villain = 1, bomb = 15,
      fish = 12, user_input;

        //Your numerous couts here.
}

int main()
{
    bool Done = false;

	while (!Done)
	{
            cout <<" please enter the direaction: " <<endl;
	    cin >> user_input;

	switch (user_input)
	{
	case 'a':
            DrawMap();
            break;
        //etc

        case 'q':
           Done = true; //If user inputs 'q' the game will end.
           break;

        default: break;
        }
    }

	return 0;
}

After that It's easier to see what's happening and then you can create a function for moving.

use loops instead of so many cout statments and i don't think the variable in the while loop is defined. I am willing to help you come with the solution if i knew what you were doing. I can't read your mind. Based on your code your don't have a default condition.

thanks for your replay *_^

no the maps are differents and that's why i can't use loop but i can use functions . i'm just know want to test my code then i can draw and arrange my code coreectly

thanks alot

That's pretty nice looking.
First, just for the sake of clearity I'd recommend making a function that draws the map.
As such:

#include <iostream>
using namespace std;

void DrawMap()
{
char wall = 177, flute = 14, hero = 2,
      life = 3, villain = 1, bomb = 15,
      fish = 12, user_input;

        //Your numerous couts here.
}

int main()
{
    bool Done = false;

	while (!Done)
	{
            cout <<" please enter the direaction: " <<endl;
	    cin >> user_input;

	switch (user_input)
	{
	case 'a':
            DrawMap();
            break;
        //etc

        case 'q':
           Done = true; //If user inputs 'q' the game will end.
           break;

        default: break;
        }
    }

	return 0;
}

After that It's easier to see what's happening and then you can create a function for moving.

wow , i'm really like your comments because it's clear to understand for the biggners such as me

thanks so much man *_^

now i'll try to do my best

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.